RakNetSocket.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /*
  11. #ifndef __RAKNET_SOCKET_H
  12. #define __RAKNET_SOCKET_H
  13. #include "RakNetTypes.h"
  14. #include "RakNetDefines.h"
  15. #include "Export.h"
  16. #include "SocketIncludes.h"
  17. #include "RakAssert.h"
  18. #include "SocketDefines.h"
  19. #include "MTUSize.h"
  20. namespace RakNet
  21. {
  22. struct RAK_DLL_EXPORT RakNetSocket
  23. {
  24. public:
  25. RakNetSocket();
  26. ~RakNetSocket();
  27. // void Accept(
  28. // struct sockaddr *addr,
  29. // int *addrlen);
  30. inline int Connect(
  31. const struct sockaddr *name,
  32. int namelen) {return connect__(s,name,namelen);}
  33. static RakNetSocket* Create
  34. #ifdef __native_client__
  35. (_PP_Instance_ _chromeInstance);
  36. #else
  37. (int af,
  38. int type,
  39. int protocol);
  40. #endif
  41. int Bind(
  42. const struct sockaddr *addr,
  43. int namelen);
  44. inline int GetSockName(
  45. struct sockaddr *name,
  46. socklen_t * namelen) {return getsockname__(s,name,namelen);}
  47. inline int GetSockOpt (
  48. int level,
  49. int optname,
  50. char * optval,
  51. socklen_t *optlen) {return getsockopt__(s,level,optname,optval,optlen);}
  52. int IOCTLSocket(
  53. long cmd,
  54. unsigned long *argp);
  55. int Listen (
  56. int backlog);
  57. inline int Recv(
  58. char * buf,
  59. int len,
  60. int flags) {return recv__(s,buf,len,flags);}
  61. inline int RecvFrom(
  62. char * buf,
  63. int len,
  64. int flags,
  65. struct sockaddr * from,
  66. socklen_t * fromlen) {return recvfrom__(s,buf,len,flags,from,fromlen);}
  67. // inline int Select(
  68. // int nfds,
  69. // fd_set *readfds,
  70. // fd_set *writefds,
  71. // fd_set *exceptfds,
  72. // struct timeval *timeout) {return select__(nfds,readfds,writefds,exceptfds,timeout);}
  73. inline int Send(
  74. const char * buf,
  75. int len,
  76. int flags) {return send__(s,buf,len,flags);}
  77. inline int SendTo(
  78. const char * buf,
  79. int len,
  80. int flags,
  81. const struct sockaddr *to,
  82. int tolen) {return sendto__(s,buf,len,flags,to,tolen);}
  83. #ifdef _WIN32
  84. #elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4) || defined(SN_TARGET_PSP2)
  85. #else
  86. inline int Fcntl(int cmd, int arg) {return fcntl(s,cmd,arg);}
  87. #endif
  88. #if defined(_WIN32) && !defined(WINDOWS_STORE_RT)
  89. inline int _WSASendTo(
  90. LPWSABUF lpBuffers,
  91. DWORD dwBufferCount,
  92. LPDWORD lpNumberOfBytesSent,
  93. DWORD dwFlags,
  94. const struct sockaddr FAR * lpTo,
  95. int iTolen,
  96. LPWSAOVERLAPPED lpOverlapped,
  97. LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
  98. )
  99. { return WSASendTo(s,lpBuffers,dwBufferCount,lpNumberOfBytesSent,dwFlags,lpTo,iTolen,lpOverlapped,lpCompletionRoutine);}
  100. #endif
  101. int SetSockOpt(
  102. int level,
  103. int optname,
  104. const char * optval,
  105. int optlen);
  106. int Shutdown(
  107. int how);
  108. inline void SetRemotePortRakNetWasStartedOn(unsigned short i) {remotePortRakNetWasStartedOn_PS3_PSP2=i;}
  109. inline void SetUserConnectionSocketIndex(unsigned int i) {userConnectionSocketIndex=i;}
  110. inline void SetBoundAddress(SystemAddress i) {boundAddress=i;}
  111. inline void SetSocketFamily(unsigned short i) {socketFamily=i;}
  112. inline void SetBlockingSocket(bool i) {blockingSocket=i;}
  113. inline void SetExtraSocketOptions(unsigned int i) {extraSocketOptions=i;}
  114. inline void SetChromeInstance(_PP_Instance_ i) {chromeInstance=i;}
  115. inline void SetBoundAddressToLoopback(unsigned char ipVersion) {boundAddress.SetToLoopback(ipVersion);}
  116. inline SystemAddress GetBoundAddress(void) const {return boundAddress;}
  117. inline unsigned short GetRemotePortRakNetWasStartedOn(void) const {return remotePortRakNetWasStartedOn_PS3_PSP2;}
  118. inline bool GetBlockingSocket(void) {return blockingSocket;}
  119. inline unsigned int GetExtraSocketOptions(void) const {return extraSocketOptions;}
  120. inline unsigned short GetSocketFamily(void) const {return socketFamily;}
  121. inline _PP_Instance_ GetChromeInstance(void) const {return chromeInstance;}
  122. inline unsigned int GetUserConnectionSocketIndex(void) const {
  123. RakAssert(userConnectionSocketIndex!=(unsigned int)-1);
  124. return userConnectionSocketIndex;}
  125. #ifdef __native_client__
  126. // Flag indicating if a SendTo is currently in progress
  127. bool sendInProgress;
  128. // Data for next queued packet to send, if nextSendSize > 0
  129. char nextSendBuffer[MAXIMUM_MTU_SIZE];
  130. // Size of next queued packet to send, or 0 if no queued packet
  131. int nextSendSize;
  132. // Destination address of queued packet
  133. PP_NetAddress_Private nextSendAddr;
  134. #endif
  135. __UDPSOCKET__ s;
  136. protected:
  137. #if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
  138. void* recvEvent;
  139. #endif
  140. #if defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4) || defined(SN_TARGET_PSP2)
  141. /// PS3: Set for the PS3, when using signaling.
  142. /// PS3: Connect with the port returned by signaling. Set this to whatever port RakNet was actually started on
  143. /// PSP2: Set non-zero to use SCE_NET_SOCK_DGRAM_P2P. This should be done for ad-hoc or with
  144. #endif
  145. unsigned short remotePortRakNetWasStartedOn_PS3_PSP2;
  146. unsigned int userConnectionSocketIndex;
  147. SystemAddress boundAddress;
  148. unsigned short socketFamily;
  149. bool blockingSocket;
  150. unsigned int extraSocketOptions;
  151. _PP_Instance_ chromeInstance;
  152. };
  153. } // namespace RakNet
  154. #endif
  155. */
粤ICP备19079148号