Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

connect_pair.hpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // local/connect_pair.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef ASIO_LOCAL_CONNECT_PAIR_HPP
  11. #define ASIO_LOCAL_CONNECT_PAIR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_HAS_LOCAL_SOCKETS) \
  17. || defined(GENERATING_DOCUMENTATION)
  18. #include "asio/basic_socket.hpp"
  19. #include "asio/detail/socket_ops.hpp"
  20. #include "asio/detail/throw_error.hpp"
  21. #include "asio/error.hpp"
  22. #include "asio/local/basic_endpoint.hpp"
  23. #include "asio/detail/push_options.hpp"
  24. namespace asio {
  25. namespace local {
  26. /// Create a pair of connected sockets.
  27. template <typename Protocol, typename SocketService1, typename SocketService2>
  28. void connect_pair(
  29. basic_socket<Protocol, SocketService1>& socket1,
  30. basic_socket<Protocol, SocketService2>& socket2);
  31. /// Create a pair of connected sockets.
  32. template <typename Protocol, typename SocketService1, typename SocketService2>
  33. asio::error_code connect_pair(
  34. basic_socket<Protocol, SocketService1>& socket1,
  35. basic_socket<Protocol, SocketService2>& socket2,
  36. asio::error_code& ec);
  37. template <typename Protocol, typename SocketService1, typename SocketService2>
  38. inline void connect_pair(
  39. basic_socket<Protocol, SocketService1>& socket1,
  40. basic_socket<Protocol, SocketService2>& socket2)
  41. {
  42. asio::error_code ec;
  43. connect_pair(socket1, socket2, ec);
  44. asio::detail::throw_error(ec, "connect_pair");
  45. }
  46. template <typename Protocol, typename SocketService1, typename SocketService2>
  47. inline asio::error_code connect_pair(
  48. basic_socket<Protocol, SocketService1>& socket1,
  49. basic_socket<Protocol, SocketService2>& socket2,
  50. asio::error_code& ec)
  51. {
  52. // Check that this function is only being used with a UNIX domain socket.
  53. asio::local::basic_endpoint<Protocol>* tmp
  54. = static_cast<typename Protocol::endpoint*>(0);
  55. (void)tmp;
  56. Protocol protocol;
  57. asio::detail::socket_type sv[2];
  58. if (asio::detail::socket_ops::socketpair(protocol.family(),
  59. protocol.type(), protocol.protocol(), sv, ec)
  60. == asio::detail::socket_error_retval)
  61. return ec;
  62. if (socket1.assign(protocol, sv[0], ec))
  63. {
  64. asio::error_code temp_ec;
  65. asio::detail::socket_ops::state_type state[2] = { 0, 0 };
  66. asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec);
  67. asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec);
  68. return ec;
  69. }
  70. if (socket2.assign(protocol, sv[1], ec))
  71. {
  72. asio::error_code temp_ec;
  73. socket1.close(temp_ec);
  74. asio::detail::socket_ops::state_type state = 0;
  75. asio::detail::socket_ops::close(sv[1], state, true, temp_ec);
  76. return ec;
  77. }
  78. return ec;
  79. }
  80. } // namespace local
  81. } // namespace asio
  82. #include "asio/detail/pop_options.hpp"
  83. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  84. // || defined(GENERATING_DOCUMENTATION)
  85. #endif // ASIO_LOCAL_CONNECT_PAIR_HPP