EmscriptenNet.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. // Portions Copyright (c) 2014 James S Urquhart
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "platformEmscripten/platformEmscripten.h"
  24. #include "platform/platform.h"
  25. #include "platform/event.h"
  26. #include "platform/platformNetAsync.unix.h"
  27. #include <unistd.h>
  28. #include <errno.h>
  29. #include <sys/time.h>
  30. // Header clean-up by William Taysom
  31. #include <sys/ioctl.h>
  32. // IPX fixes from William Taysom.
  33. #define IPX_NODE_LEN 6
  34. // for 10.2 compatability...
  35. #ifndef socklen_t
  36. #define socklen_t unsigned int
  37. #endif
  38. #include <stdlib.h>
  39. #include "console/console.h"
  40. #include "game/gameInterface.h"
  41. #include "io/fileStream.h"
  42. #include "collection/vector.h"
  43. static Net::Error getLastError();
  44. static S32 defaultPort = 28000;
  45. static S32 netPort = 0;
  46. static int ipxSocket = InvalidSocket;
  47. static int udpSocket = InvalidSocket;
  48. // local enum for socket states for polled sockets
  49. enum SocketState
  50. {
  51. InvalidState,
  52. Connected,
  53. ConnectionPending,
  54. Listening,
  55. NameLookupRequired
  56. };
  57. bool Net::init()
  58. {
  59. return(true);
  60. }
  61. void Net::shutdown()
  62. {
  63. }
  64. NetSocket Net::openListenPort(U16 port)
  65. {
  66. Con::errorf("Sockets not implemented on Emscripten");
  67. return InvalidSocket;
  68. }
  69. NetSocket Net::openConnectTo(const char *addressString)
  70. {
  71. Con::errorf("Sockets not implemented on Emscripten");
  72. return InvalidSocket;
  73. }
  74. void Net::closeConnectTo(NetSocket sock)
  75. {
  76. }
  77. Net::Error Net::sendtoSocket(NetSocket socket, const U8 *buffer, int bufferSize)
  78. {
  79. return NoError;
  80. }
  81. bool Net::openPort(S32 port)
  82. {
  83. return false;
  84. }
  85. void Net::closePort()
  86. {
  87. }
  88. Net::Error Net::sendto(const NetAddress *address, const U8 *buffer, S32 bufferSize)
  89. {
  90. return NoError;
  91. }
  92. void Net::process()
  93. {
  94. }
  95. NetSocket Net::openSocket()
  96. {
  97. return InvalidSocket;
  98. }
  99. Net::Error Net::closeSocket(NetSocket socket)
  100. {
  101. return NoError;
  102. }
  103. Net::Error Net::connect(NetSocket socket, const NetAddress *address)
  104. {
  105. return NoError;
  106. }
  107. Net::Error Net::listen(NetSocket socket, S32 backlog)
  108. {
  109. return NoError;
  110. }
  111. NetSocket Net::accept(NetSocket acceptSocket, NetAddress *remoteAddress)
  112. {
  113. return InvalidSocket;
  114. }
  115. Net::Error Net::bind(NetSocket socket, U16 port)
  116. {
  117. return NoError;
  118. }
  119. Net::Error Net::setBufferSize(NetSocket socket, S32 bufferSize)
  120. {
  121. return NoError;
  122. }
  123. Net::Error Net::setBroadcast(NetSocket socket, bool broadcast)
  124. {
  125. return NoError;
  126. }
  127. Net::Error Net::setBlocking(NetSocket socket, bool blockingIO)
  128. {
  129. return NoError;
  130. }
  131. Net::Error Net::send(NetSocket socket, const U8 *buffer, S32 bufferSize)
  132. {
  133. return NoError;
  134. }
  135. Net::Error Net::recv(NetSocket socket, U8 *buffer, S32 bufferSize, S32 *bytesRead)
  136. {
  137. return NoError;
  138. }
  139. bool Net::compareAddresses(const NetAddress *a1, const NetAddress *a2)
  140. {
  141. if((a1->type != a2->type) ||
  142. (*((U32 *)a1->netNum) != *((U32 *)a2->netNum)) ||
  143. (a1->port != a2->port))
  144. return false;
  145. if(a1->type == NetAddress::IPAddress)
  146. return true;
  147. for(S32 i = 0; i < 6; i++)
  148. if(a1->nodeNum[i] != a2->nodeNum[i])
  149. return false;
  150. return true;
  151. }
  152. bool Net::stringToAddress(const char *addressString, NetAddress *address)
  153. {
  154. return false;
  155. }
  156. void Net::addressToString(const NetAddress *address, char addressString[256])
  157. {
  158. addressString[0] = '\0';
  159. }
  160. Net::Error getLastError()
  161. {
  162. return Net::UnknownError;
  163. }