/Src/Dependencies/Boost/boost/asio/local/detail/endpoint.hpp

http://hadesmem.googlecode.com/ · C++ Header · 135 lines · 76 code · 30 blank · 29 comment · 1 complexity · 9d2867ee5a3050277d7cd67d2d0f4be4 MD5 · raw file

  1. //
  2. // local/detail/endpoint.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Derived from a public domain implementation written by Daniel Casimiro.
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
  12. #define BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
  18. #include <cstddef>
  19. #include <string>
  20. #include <boost/asio/detail/socket_types.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace local {
  25. namespace detail {
  26. // Helper class for implementing a UNIX domain endpoint.
  27. class endpoint
  28. {
  29. public:
  30. // Default constructor.
  31. BOOST_ASIO_DECL endpoint();
  32. // Construct an endpoint using the specified path name.
  33. BOOST_ASIO_DECL endpoint(const char* path_name);
  34. // Construct an endpoint using the specified path name.
  35. BOOST_ASIO_DECL endpoint(const std::string& path_name);
  36. // Copy constructor.
  37. endpoint(const endpoint& other)
  38. : data_(other.data_),
  39. path_length_(other.path_length_)
  40. {
  41. }
  42. // Assign from another endpoint.
  43. endpoint& operator=(const endpoint& other)
  44. {
  45. data_ = other.data_;
  46. path_length_ = other.path_length_;
  47. return *this;
  48. }
  49. // Get the underlying endpoint in the native type.
  50. boost::asio::detail::socket_addr_type* data()
  51. {
  52. return &data_.base;
  53. }
  54. // Get the underlying endpoint in the native type.
  55. const boost::asio::detail::socket_addr_type* data() const
  56. {
  57. return &data_.base;
  58. }
  59. // Get the underlying size of the endpoint in the native type.
  60. std::size_t size() const
  61. {
  62. return path_length_
  63. + offsetof(boost::asio::detail::sockaddr_un_type, sun_path);
  64. }
  65. // Set the underlying size of the endpoint in the native type.
  66. BOOST_ASIO_DECL void resize(std::size_t size);
  67. // Get the capacity of the endpoint in the native type.
  68. std::size_t capacity() const
  69. {
  70. return sizeof(boost::asio::detail::sockaddr_un_type);
  71. }
  72. // Get the path associated with the endpoint.
  73. BOOST_ASIO_DECL std::string path() const;
  74. // Set the path associated with the endpoint.
  75. BOOST_ASIO_DECL void path(const char* p);
  76. // Set the path associated with the endpoint.
  77. BOOST_ASIO_DECL void path(const std::string& p);
  78. // Compare two endpoints for equality.
  79. BOOST_ASIO_DECL friend bool operator==(
  80. const endpoint& e1, const endpoint& e2);
  81. // Compare endpoints for ordering.
  82. BOOST_ASIO_DECL friend bool operator<(
  83. const endpoint& e1, const endpoint& e2);
  84. private:
  85. // The underlying UNIX socket address.
  86. union data_union
  87. {
  88. boost::asio::detail::socket_addr_type base;
  89. boost::asio::detail::sockaddr_un_type local;
  90. } data_;
  91. // The length of the path associated with the endpoint.
  92. std::size_t path_length_;
  93. // Initialise with a specified path.
  94. BOOST_ASIO_DECL void init(const char* path, std::size_t path_length);
  95. };
  96. } // namespace detail
  97. } // namespace local
  98. } // namespace asio
  99. } // namespace boost
  100. #include <boost/asio/detail/pop_options.hpp>
  101. #if defined(BOOST_ASIO_HEADER_ONLY)
  102. # include <boost/asio/local/detail/impl/endpoint.ipp>
  103. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  104. #endif // defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
  105. #endif // BOOST_ASIO_LOCAL_DETAIL_ENDPOINT_HPP