![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 #ifndef __SOCKET_LAYER_H 00011 #define __SOCKET_LAYER_H 00012 00013 #include "RakMemoryOverride.h" 00014 #include "SocketIncludes.h" 00015 #include "RakNetTypes.h" 00016 #include "RakNetSmartPtr.h" 00017 #include "RakNetSocket.h" 00018 #include "Export.h" 00019 #include "MTUSize.h" 00020 #include "RakString.h" 00021 00022 //#include "ClientContextStruct.h" 00023 00024 namespace RakNet 00025 { 00027 class RakPeer; 00028 00029 class RAK_DLL_EXPORT SocketLayerOverride 00030 { 00031 public: 00032 SocketLayerOverride() {} 00033 virtual ~SocketLayerOverride() {} 00034 00036 virtual int RakNetSendTo( SOCKET s, const char *data, int length, const SystemAddress &systemAddress )=0; 00037 00039 // Return -1 to use RakNet's normal recvfrom, 0 to abort RakNet's normal recvfrom, and positive to return data 00040 virtual int RakNetRecvFrom( const SOCKET sIn, RakPeer *rakPeerIn, char dataOut[ MAXIMUM_MTU_SIZE ], SystemAddress *senderOut, bool calledFromMainThread )=0; 00041 }; 00042 00043 00044 // A platform independent implementation of Berkeley sockets, with settings used by RakNet 00045 class RAK_DLL_EXPORT SocketLayer 00046 { 00047 00048 public: 00049 00051 SocketLayer(); 00052 00053 // Destructor 00054 ~SocketLayer(); 00055 00060 static SOCKET CreateBoundSocket( unsigned short port, bool blockingSocket, const char *forceHostAddress, unsigned int sleepOn10048, unsigned int extraSocketOptions, unsigned short socketFamily ); 00061 static SOCKET CreateBoundSocket_Old( unsigned short port, bool blockingSocket, const char *forceHostAddress, unsigned int sleepOn10048, unsigned int extraSocketOptions ); 00062 static SOCKET CreateBoundSocket_PS3Lobby( unsigned short port, bool blockingSocket, const char *forceHostAddress, unsigned short socketFamily ); 00063 static SOCKET CreateBoundSocket_PSP2( unsigned short port, bool blockingSocket, const char *forceHostAddress, unsigned short socketFamily ); 00064 00068 static bool IsPortInUse_Old(unsigned short port, const char *hostAddress); 00069 static bool IsPortInUse(unsigned short port, const char *hostAddress, unsigned short socketFamily ); 00070 static bool IsSocketFamilySupported(const char *hostAddress, unsigned short socketFamily); 00071 00072 static const char* DomainNameToIP_Old( const char *domainName ); 00073 static const char* DomainNameToIP( const char *domainName ); 00074 00079 static void Write( const SOCKET writeSocket, const char* data, const int length ); 00080 00087 static void RecvFromBlocking_Old( const SOCKET s, RakPeer *rakPeer, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, char *dataOut, int *bytesReadOut, SystemAddress *systemAddressOut, RakNet::TimeUS *timeRead ); 00088 static void RecvFromBlocking( const SOCKET s, RakPeer *rakPeer, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, char *dataOut, int *bytesReadOut, SystemAddress *systemAddressOut, RakNet::TimeUS *timeRead ); 00089 00094 static RakNet::RakString GetSubNetForSocketAndIp(SOCKET inSock, RakNet::RakString inIpString); 00095 00096 00099 static void SetNonBlocking( SOCKET listenSocket); 00100 00101 00105 static void GetMyIP( SystemAddress addresses[MAXIMUM_NUMBER_OF_INTERNAL_IDS] ); 00106 00107 00115 // static int SendTo( SOCKET s, const char *data, int length, const char ip[ 16 ], unsigned short port, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, const char *file, const long line ); 00116 00127 static int SendToTTL( SOCKET s, const char *data, int length, SystemAddress &systemAddress, int ttl ); 00128 00136 static int SendTo( SOCKET s, const char *data, int length, SystemAddress &systemAddress, unsigned short remotePortRakNetWasStartedOn_PS3, unsigned int extraSocketOptions, const char *file, const long line ); 00137 00138 static unsigned short GetLocalPort(SOCKET s); 00139 static void GetSystemAddress_Old ( SOCKET s, SystemAddress *systemAddressOut ); 00140 static void GetSystemAddress ( SOCKET s, SystemAddress *systemAddressOut ); 00141 00142 static void SetSocketLayerOverride(SocketLayerOverride *_slo); 00143 static SocketLayerOverride* GetSocketLayerOverride(void) {return slo;} 00144 00145 static int SendTo_PS3Lobby( SOCKET s, const char *data, int length, const SystemAddress &systemAddress, unsigned short remotePortRakNetWasStartedOn_PS3 ); 00146 static int SendTo_PSP2( SOCKET s, const char *data, int length, const SystemAddress &systemAddress, unsigned short remotePortRakNetWasStartedOn_PS3 ); 00147 static int SendTo_360( SOCKET s, const char *data, int length, const char *voiceData, int voiceLength, const SystemAddress &systemAddress, unsigned int extraSocketOptions ); 00148 static int SendTo_PC( SOCKET s, const char *data, int length, const SystemAddress &systemAddress, const char *file, const long line ); 00149 00150 static void SetDoNotFragment( SOCKET listenSocket, int opt, int IPPROTO ); 00151 00152 00153 // AF_INET (default). For IPV6, use AF_INET6. To autoselect, use AF_UNSPEC. 00154 static bool GetFirstBindableIP(char firstBindable[128], int ipProto); 00155 00156 private: 00157 00158 static void SetSocketOptions( SOCKET listenSocket); 00159 static SocketLayerOverride *slo; 00160 }; 00161 00162 } // namespace RakNet 00163 00164 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.