log4cplus  1.1.0
socket.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // Module:  Log4CPLUS
00003 // File:    socket.h
00004 // Created: 1/2010
00005 // Author:  Vaclav Haisman
00006 //
00007 //
00008 //  Copyright (C) 2010, Vaclav Haisman. All rights reserved.
00009 //  
00010 //  Redistribution and use in source and binary forms, with or without modifica-
00011 //  tion, are permitted provided that the following conditions are met:
00012 //  
00013 //  1. Redistributions of  source code must  retain the above copyright  notice,
00014 //     this list of conditions and the following disclaimer.
00015 //  
00016 //  2. Redistributions in binary form must reproduce the above copyright notice,
00017 //     this list of conditions and the following disclaimer in the documentation
00018 //     and/or other materials provided with the distribution.
00019 //  
00020 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
00021 //  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00022 //  FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
00023 //  APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
00024 //  INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
00025 //  DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
00026 //  OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
00027 //  ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
00028 //  (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
00029 //  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00037 #ifndef LOG4CPLUS_INTERNAL_SOCKET_H_
00038 #define LOG4CPLUS_INTERNAL_SOCKET_H_
00039 
00040 #include <log4cplus/config.hxx>
00041 
00042 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
00043 #pragma once
00044 #endif
00045 
00046 #if ! defined (INSIDE_LOG4CPLUS)
00047 #  error "This header must not be be used outside log4cplus' implementation files."
00048 #endif
00049 
00050 #if defined(_WIN32)
00051 #include <log4cplus/config/windowsh-inc.h>
00052 #endif
00053 #include <log4cplus/helpers/socket.h>
00054 
00055 #include <cerrno>
00056 #ifdef LOG4CPLUS_HAVE_ERRNO_H
00057 #include <errno.h>
00058 #endif
00059 
00060 
00061 namespace log4cplus {
00062 
00063 namespace helpers {
00064 
00065 
00066 #if defined(_WIN32)
00067 typedef SOCKET os_socket_type;
00068 #else
00069 typedef int os_socket_type;
00070 #endif
00071 
00072 
00073 os_socket_type const INVALID_OS_SOCKET_VALUE
00074 #if defined(_WIN32)
00075     = INVALID_SOCKET;
00076 #else
00077     = -1;
00078 #endif
00079 
00080 
00081 static inline
00082 os_socket_type
00083 to_os_socket (SOCKET_TYPE const & x)
00084 {
00085     return static_cast<os_socket_type>(x);
00086 }
00087 
00088 
00089 static inline
00090 SOCKET_TYPE
00091 to_log4cplus_socket (os_socket_type const & x)
00092 {
00093     return static_cast<SOCKET_TYPE>(x);
00094 }
00095 
00096 
00097 static inline
00098 void
00099 set_last_socket_error (int err)
00100 {
00101     errno = err;
00102 }
00103 
00104 
00105 static inline
00106 int
00107 get_last_socket_error ()
00108 {
00109     return errno;
00110 }
00111 
00112 
00113 } // namespace helpers {
00114 
00115 } // namespace log4cplus { 
00116 
00117 
00118 #endif // LOG4CPLUS_INTERNAL_SOCKET_H_