PageRenderTime 71ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/SFML/Network/Win32/SocketImpl.hpp

http://github.com/LaurentGomila/SFML
C++ Header | 112 lines | 30 code | 14 blank | 68 comment | 0 complexity | 3c32071b74448c8a7545590ac2ebd3c0 MD5 | raw file
  1. ////////////////////////////////////////////////////////////
  2. //
  3. // SFML - Simple and Fast Multimedia Library
  4. // Copyright (C) 2007-2019 Laurent Gomila (laurent@sfml-dev.org)
  5. //
  6. // This software is provided 'as-is', without any express or implied warranty.
  7. // In no event will the authors be held liable for any damages arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it freely,
  11. // subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented;
  14. // you must not claim that you wrote the original software.
  15. // If you use this software in a product, an acknowledgment
  16. // in the product documentation would be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such,
  19. // and must not be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. ////////////////////////////////////////////////////////////
  24. #ifndef SFML_SOCKETIMPL_HPP
  25. #define SFML_SOCKETIMPL_HPP
  26. ////////////////////////////////////////////////////////////
  27. // Headers
  28. ////////////////////////////////////////////////////////////
  29. #ifdef _WIN32_WINDOWS
  30. #undef _WIN32_WINDOWS
  31. #endif
  32. #ifdef _WIN32_WINNT
  33. #undef _WIN32_WINNT
  34. #endif
  35. #define _WIN32_WINDOWS 0x0501
  36. #define _WIN32_WINNT 0x0501
  37. #include <SFML/Network/Socket.hpp>
  38. #include <winsock2.h>
  39. #include <ws2tcpip.h>
  40. namespace sf
  41. {
  42. namespace priv
  43. {
  44. ////////////////////////////////////////////////////////////
  45. /// \brief Helper class implementing all the non-portable
  46. /// socket stuff; this is the Windows version
  47. ///
  48. ////////////////////////////////////////////////////////////
  49. class SocketImpl
  50. {
  51. public:
  52. ////////////////////////////////////////////////////////////
  53. // Types
  54. ////////////////////////////////////////////////////////////
  55. typedef int AddrLength;
  56. ////////////////////////////////////////////////////////////
  57. /// \brief Create an internal sockaddr_in address
  58. ///
  59. /// \param address Target address
  60. /// \param port Target port
  61. ///
  62. /// \return sockaddr_in ready to be used by socket functions
  63. ///
  64. ////////////////////////////////////////////////////////////
  65. static sockaddr_in createAddress(Uint32 address, unsigned short port);
  66. ////////////////////////////////////////////////////////////
  67. /// \brief Return the value of the invalid socket
  68. ///
  69. /// \return Special value of the invalid socket
  70. ///
  71. ////////////////////////////////////////////////////////////
  72. static SocketHandle invalidSocket();
  73. ////////////////////////////////////////////////////////////
  74. /// \brief Close and destroy a socket
  75. ///
  76. /// \param sock Handle of the socket to close
  77. ///
  78. ////////////////////////////////////////////////////////////
  79. static void close(SocketHandle sock);
  80. ////////////////////////////////////////////////////////////
  81. /// \brief Set a socket as blocking or non-blocking
  82. ///
  83. /// \param sock Handle of the socket
  84. /// \param block New blocking state of the socket
  85. ///
  86. ////////////////////////////////////////////////////////////
  87. static void setBlocking(SocketHandle sock, bool block);
  88. ////////////////////////////////////////////////////////////
  89. /// Get the last socket error status
  90. ///
  91. /// \return Status corresponding to the last socket error
  92. ///
  93. ////////////////////////////////////////////////////////////
  94. static Socket::Status getErrorStatus();
  95. };
  96. } // namespace priv
  97. } // namespace sf
  98. #endif // SFML_SOCKETIMPL_HPP