RakNetSocket.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #include "RakNetSocket.h"
  12. #include "RakMemoryOverride.h"
  13. using namespace RakNet;
  14. #if defined(__native_client__)
  15. using namespace pp;
  16. #endif
  17. RakNetSocket::RakNetSocket() {
  18. #if !defined(WINDOWS_STORE_RT)
  19. s = 0;
  20. #endif
  21. remotePortRakNetWasStartedOn_PS3_PSP2 = 0;
  22. userConnectionSocketIndex = (unsigned int) -1;
  23. socketFamily = 0;
  24. blockingSocket = 0;
  25. extraSocketOptions = 0;
  26. chromeInstance = 0;
  27. #if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
  28. recvEvent=INVALID_HANDLE_VALUE;
  29. #endif
  30. #ifdef __native_client__
  31. s = 0;
  32. sendInProgress = false;
  33. nextSendSize = 0;
  34. #endif
  35. }
  36. RakNetSocket::~RakNetSocket()
  37. {
  38. #ifdef __native_client__
  39. if(s != 0)
  40. ((PPB_UDPSocket_Private_0_4*) pp::Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4))->Close(s);
  41. #elif defined(WINDOWS_STORE_RT)
  42. WinRTClose(s);
  43. #else
  44. if ((__UDPSOCKET__)s != 0)
  45. closesocket__(s);
  46. #endif
  47. #if defined (_WIN32) && defined(USE_WAIT_FOR_MULTIPLE_EVENTS)
  48. if (recvEvent!=INVALID_HANDLE_VALUE)
  49. {
  50. CloseHandle( recvEvent );
  51. recvEvent = INVALID_HANDLE_VALUE;
  52. }
  53. #endif
  54. }
  55. //
  56. // void RakNetSocket::Accept(
  57. // struct sockaddr *addr,
  58. // int *addrlen)
  59. // {
  60. // accept__(s, addr, addrlen);
  61. // }
  62. //
  63. // void RakNetSocket::Close( void )
  64. // {
  65. // closesocket__(s);
  66. // }
  67. RakNetSocket* RakNetSocket::Create
  68. #ifdef __native_client__
  69. (_PP_Instance_ _chromeInstance)
  70. #else
  71. (int af,
  72. int type,
  73. int protocol)
  74. #endif
  75. {
  76. __UDPSOCKET__ sock;
  77. #ifndef __native_client__
  78. RakAssert(type==SOCK_DGRAM);
  79. #endif
  80. #ifdef __native_client__
  81. sock = ((PPB_UDPSocket_Private_0_4*) Module::Get()->GetBrowserInterface(PPB_UDPSOCKET_PRIVATE_INTERFACE_0_4))->Create(_chromeInstance);
  82. #elif defined(SN_TARGET_PSP2)
  83. sock = sceNetSocket( "RakNetSocket::Create", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM_P2P, 0 );
  84. #elif defined(WINDOWS_STORE_RT)
  85. sock = WinRTCreateDatagramSocket(af,type,protocol);
  86. #elif defined(_PS3) || defined(__PS3__) || defined(SN_TARGET_PS3) || defined(_PS4)
  87. sock = socket__( AF_INET, SOCK_DGRAM_P2P, 0 );
  88. #else
  89. sock = socket__(af, type, protocol);
  90. #endif
  91. #if !defined(WINDOWS_STORE_RT)
  92. if (sock<0)
  93. return 0;
  94. #endif
  95. RakNetSocket *rns = RakNet::OP_NEW<RakNetSocket>(_FILE_AND_LINE_);
  96. rns->s = sock;
  97. #ifdef __native_client__
  98. rns->chromeInstance = _chromeInstance;
  99. #endif
  100. return rns;
  101. }
  102. int RakNetSocket::Bind(
  103. const struct sockaddr *addr,
  104. int namelen)
  105. {
  106. return bind__(s,addr,namelen);
  107. }
  108. int RakNetSocket::IOCTLSocket(
  109. long cmd,
  110. unsigned long *argp)
  111. {
  112. #if defined(_WIN32)
  113. return ioctlsocket__(s,cmd,argp);
  114. #else
  115. return 0;
  116. #endif
  117. }
  118. int RakNetSocket::Listen (
  119. int backlog)
  120. {
  121. return listen__(s,backlog);
  122. }
  123. int RakNetSocket::SetSockOpt(
  124. int level,
  125. int optname,
  126. const char * optval,
  127. int optlen)
  128. {
  129. return setsockopt__(s,level,optname,optval,optlen);
  130. }
  131. int RakNetSocket::Shutdown(
  132. int how)
  133. {
  134. #ifndef SN_TARGET_PSP2
  135. return shutdown__(s,how);
  136. #else
  137. return 0;
  138. #endif
  139. }
  140. */
粤ICP备19079148号