PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/SFML/Network/Unix/SocketImpl.hpp

http://github.com/LaurentGomila/SFML
C++ Header | 109 lines | 27 code | 14 blank | 68 comment | 0 complexity | 19ea04ba981af7c2c75112b880afde9f 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. #include <SFML/Network/Socket.hpp>
  30. #include <sys/types.h>
  31. #include <sys/socket.h>
  32. #include <netinet/in.h>
  33. #include <netinet/tcp.h>
  34. #include <arpa/inet.h>
  35. #include <netdb.h>
  36. #include <unistd.h>
  37. namespace sf
  38. {
  39. namespace priv
  40. {
  41. ////////////////////////////////////////////////////////////
  42. /// \brief Helper class implementing all the non-portable
  43. /// socket stuff; this is the Unix version
  44. ///
  45. ////////////////////////////////////////////////////////////
  46. class SocketImpl
  47. {
  48. public:
  49. ////////////////////////////////////////////////////////////
  50. // Types
  51. ////////////////////////////////////////////////////////////
  52. typedef socklen_t AddrLength;
  53. ////////////////////////////////////////////////////////////
  54. /// \brief Create an internal sockaddr_in address
  55. ///
  56. /// \param address Target address
  57. /// \param port Target port
  58. ///
  59. /// \return sockaddr_in ready to be used by socket functions
  60. ///
  61. ////////////////////////////////////////////////////////////
  62. static sockaddr_in createAddress(Uint32 address, unsigned short port);
  63. ////////////////////////////////////////////////////////////
  64. /// \brief Return the value of the invalid socket
  65. ///
  66. /// \return Special value of the invalid socket
  67. ///
  68. ////////////////////////////////////////////////////////////
  69. static SocketHandle invalidSocket();
  70. ////////////////////////////////////////////////////////////
  71. /// \brief Close and destroy a socket
  72. ///
  73. /// \param sock Handle of the socket to close
  74. ///
  75. ////////////////////////////////////////////////////////////
  76. static void close(SocketHandle sock);
  77. ////////////////////////////////////////////////////////////
  78. /// \brief Set a socket as blocking or non-blocking
  79. ///
  80. /// \param sock Handle of the socket
  81. /// \param block New blocking state of the socket
  82. ///
  83. ////////////////////////////////////////////////////////////
  84. static void setBlocking(SocketHandle sock, bool block);
  85. ////////////////////////////////////////////////////////////
  86. /// Get the last socket error status
  87. ///
  88. /// \return Status corresponding to the last socket error
  89. ///
  90. ////////////////////////////////////////////////////////////
  91. static Socket::Status getErrorStatus();
  92. };
  93. } // namespace priv
  94. } // namespace sf
  95. #endif // SFML_SOCKETIMPL_HPP