blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005, Vintela, Inc. All rights reserved. 00003 * Copyright (C) 2006, Novell, Inc. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of 00014 * Vintela, Inc., 00015 * nor Novell, Inc., 00016 * nor the names of its contributors or employees may be used to 00017 * endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 *******************************************************************************/ 00032 00033 00039 #ifndef BLOCXX_NETWORK_TYPES_HPP_INCLUDE_GUARD_ 00040 #define BLOCXX_NETWORK_TYPES_HPP_INCLUDE_GUARD_ 00041 #include "blocxx/BLOCXX_config.h" 00042 #include "blocxx/Types.hpp" 00043 00044 extern "C" 00045 { 00046 #ifdef BLOCXX_HAVE_UNISTD_H 00047 #include <unistd.h> 00048 #endif 00049 00050 #include <signal.h> 00051 00052 #ifdef BLOCXX_HAVE_SYS_SOCKET_H 00053 #include <sys/socket.h> 00054 #endif 00055 00056 #ifdef BLOCXX_HAVE_NETINET_IN_H 00057 #include <netinet/in.h> 00058 #endif 00059 00060 #ifdef BLOCXX_HAVE_SYS_UN_H 00061 #include <sys/un.h> 00062 #endif 00063 00064 #if defined(BLOCXX_WIN32) 00065 #include <winsock2.h> 00066 #endif 00067 } 00068 00069 #undef shutdown // On OpenUnix, sys/socket.h defines shutdown to be 00070 // _shutdown. (which breaks HTTPServer, etc.) 00071 00072 namespace BLOCXX_NAMESPACE 00073 { 00074 00075 // Platform specific socket address type 00076 typedef sockaddr SocketAddress_t; 00077 // Platform specific inet socket address type 00078 #ifdef BLOCXX_HAVE_IPV6 00079 typedef sockaddr_storage InetSocketAddress_t; 00080 #else 00081 typedef sockaddr_in InetSocketAddress_t; 00082 #endif 00083 00084 #if !defined(BLOCXX_WIN32) 00085 // Platform specific unix socket address type 00086 typedef sockaddr_un UnixSocketAddress_t; 00087 #endif 00088 00089 // Platform specific socket address type 00090 typedef in_addr InetAddress_t; 00091 00092 #if defined (BLOCXX_WIN32) 00093 // Platform specific socket fd type 00094 typedef SOCKET SocketHandle_t; 00095 #else 00096 // Platform specific socket fd type 00097 typedef int SocketHandle_t; 00098 #endif 00099 00100 // Select_t is the type of object that can be used in 00101 // synchronous I/O multiplexing (i.e. select). 00102 #if defined(BLOCXX_WIN32) 00103 struct Select_t 00104 { 00105 Select_t() 00106 : event(NULL) 00107 , descriptor(INVALID_HANDLE_VALUE) 00108 , sockfd(INVALID_SOCKET) 00109 , isSocket(false) 00110 , networkevents(0) 00111 , doreset(false) 00112 { 00113 } 00114 00115 Select_t(const Select_t& arg) 00116 : event(arg.event) 00117 , descriptor(arg.descriptor) 00118 , sockfd(arg.sockfd) 00119 , isSocket(arg.isSocket) 00120 , networkevents(arg.networkevents) 00121 , doreset(arg.doreset) 00122 { 00123 } 00124 00125 HANDLE event; 00126 HANDLE descriptor; 00127 SOCKET sockfd; 00128 bool isSocket; 00129 bool doreset; 00130 long networkevents; 00131 00132 bool operator<(const Select_t& s1) const 00133 { 00134 //we can not use the fields 'sockfd' or 'descriptor' because it's possible 00135 //the comparison of objects with different types - SOCKET and HANDLE 00136 //but the field 'event' is presented for both types 00137 return (event < s1.event); 00138 } 00139 00140 bool operator==(const Select_t& s1) const 00141 { 00142 return (event == s1.event); 00143 } 00144 }; 00145 #else 00146 typedef int Select_t; 00147 #endif 00148 00149 } // end namespace BLOCXX_NAMESPACE 00150 00151 #if defined(BLOCXX_WIN32) || defined(BLOCXX_NCR) 00152 typedef int socklen_t; 00153 #else 00154 #ifndef BLOCXX_HAVE_SOCKLEN_T 00155 typedef unsigned socklen_t; 00156 #endif 00157 #endif 00158 00159 00160 #endif