Vault
4.1
|
00001 /* 00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved. 00003 This file is part of the Code Vault version 4.1 00004 http://www.bombaydigital.com/ 00005 License: MIT. See LICENSE.md in the Vault top level directory. 00006 */ 00007 00008 #ifndef vsocket_platform_h 00009 #define vsocket_platform_h 00010 00013 // This file is intended to be include *by* the generic vsocket.h to get 00014 // any platform-specific declarations or includes. 00015 00016 #ifndef PP_Target_Carbon 00017 // Unix platform includes needed for platform socket implementation. 00018 #include <sys/socket.h> 00019 #include <netinet/in.h> 00020 #include <netinet/tcp.h> 00021 #endif 00022 00023 #include <netdb.h> 00024 #include <arpa/inet.h> 00025 00026 // On Mac OS X, we disable SIGPIPE in VSocket::setDefaultSockOpt(), so these flags are 0. 00027 // On Winsock, it is irrelevant so these flags are 0. 00028 // For other Unix platforms, we specify it in the flags of each send()/recv() call via this parameter. 00029 #ifdef VPLATFORM_UNIX 00030 #define VSOCKET_DEFAULT_SEND_FLAGS MSG_NOSIGNAL 00031 #define VSOCKET_DEFAULT_RECV_FLAGS MSG_NOSIGNAL 00032 #else 00033 #define VSOCKET_DEFAULT_SEND_FLAGS 0 00034 #define VSOCKET_DEFAULT_RECV_FLAGS 0 00035 #endif 00036 00037 /* 00038 There are a couple of Unix APIs we call that take a socklen_t parameter. 00039 Well, on HP-UX the parameter is defined as an int. The cleanest way of dealing 00040 with this is to have our own conditionally-defined type here and use it there. 00041 */ 00042 #ifdef VPLATFORM_UNIX_HPUX 00043 typedef int VSocklenT; 00044 #else 00045 typedef socklen_t VSocklenT; 00046 #endif 00047 00048 typedef int VSocketID; 00049 #define V_NO_SOCKET_ID_CONSTANT -1 ///< Used internally to initialize kNoSocketID 00050 00051 // Winsock uses slightly incompatible socket APIs with different types. We can usually just 00052 // typecast, and rather than have different versions of the code we can name the typecasts 00053 // and declare them differently per platform. For Unix the casts usually are "nothing". 00054 #define v_ioctlsocket ioctl /* varargs make this easier than an inline function */ 00055 #define SelectSockIDTypeCast 00056 #define SendBufferPtrTypeCast 00057 #define RecvBufferPtrTypeCast 00058 #define SendRecvByteCountTypeCast (VSizeType) 00059 #define SendRecvResultTypeCast (int) 00060 #define SetSockOptValueTypeCast 00061 00062 namespace vault { 00063 inline int closeSocket(VSocketID fd) { return ::close(fd); } 00064 } 00065 00066 #endif /* vsocket_platform_h */ 00067