RakNetSocket2_Windows_Linux_360.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "EmptyHeader.h"
  11. #ifdef RAKNET_SOCKET_2_INLINE_FUNCTIONS
  12. #ifndef RAKNETSOCKET2_WINDOWS_LINUX_360_CPP
  13. #define RAKNETSOCKET2_WINDOWS_LINUX_360_CPP
  14. #if (defined(_WIN32) || defined(__GNUC__) || defined(__GCCXML__) || defined(__S3E__) ) && !defined(WINDOWS_STORE_RT) && !defined(__native_client__)
  15. RNS2SendResult RNS2_Windows_Linux_360::Send_Windows_Linux_360NoVDP( RNS2Socket rns2Socket, RNS2_SendParameters *sendParameters, const char *file, unsigned int line ) {
  16. int len=0;
  17. do
  18. {
  19. (void) file;
  20. (void) line;
  21. int oldTTL=-1;
  22. if (sendParameters->ttl>0)
  23. {
  24. socklen_t opLen=sizeof(oldTTL);
  25. // Get the current TTL
  26. if (getsockopt__(rns2Socket, sendParameters->systemAddress.GetIPPROTO(), IP_TTL, ( char * ) & oldTTL, &opLen ) != -1)
  27. {
  28. int newTTL=sendParameters->ttl;
  29. setsockopt__(rns2Socket, sendParameters->systemAddress.GetIPPROTO(), IP_TTL, ( char * ) & newTTL, sizeof ( newTTL ) );
  30. }
  31. }
  32. if (sendParameters->systemAddress.address.addr4.sin_family==AF_INET)
  33. {
  34. len = sendto__( rns2Socket, sendParameters->data, sendParameters->length, 0, ( const sockaddr* ) & sendParameters->systemAddress.address.addr4, sizeof( sockaddr_in ) );
  35. }
  36. else
  37. {
  38. #if RAKNET_SUPPORT_IPV6==1
  39. len = sendto__( rns2Socket, sendParameters->data, sendParameters->length, 0, ( const sockaddr* ) & sendParameters->systemAddress.address.addr6, sizeof( sockaddr_in6 ) );
  40. #endif
  41. }
  42. if (len<0)
  43. {
  44. RAKNET_DEBUG_PRINTF("sendto failed with code %i for char %i and length %i.\n", len, sendParameters->data[0], sendParameters->length);
  45. }
  46. if (oldTTL!=-1)
  47. {
  48. setsockopt__(rns2Socket, sendParameters->systemAddress.GetIPPROTO(), IP_TTL, ( char * ) & oldTTL, sizeof ( oldTTL ) );
  49. }
  50. }
  51. while ( len == 0 );
  52. return len;
  53. }
  54. #endif // Windows, Linux, 360
  55. #endif // file header
  56. #endif // #ifdef RAKNET_SOCKET_2_INLINE_FUNCTIONS
粤ICP备19079148号