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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // local/connect_pair.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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 Executor1, typename Executor2>
  28. void connect_pair(basic_socket<Protocol, Executor1>& socket1,
  29. basic_socket<Protocol, Executor2>& socket2);
  30. /// Create a pair of connected sockets.
  31. template <typename Protocol, typename Executor1, typename Executor2>
  32. ASIO_SYNC_OP_VOID connect_pair(basic_socket<Protocol, Executor1>& socket1,
  33. basic_socket<Protocol, Executor2>& socket2, asio::error_code& ec);
  34. template <typename Protocol, typename Executor1, typename Executor2>
  35. inline void connect_pair(basic_socket<Protocol, Executor1>& socket1,
  36. basic_socket<Protocol, Executor2>& socket2)
  37. {
  38. asio::error_code ec;
  39. connect_pair(socket1, socket2, ec);
  40. asio::detail::throw_error(ec, "connect_pair");
  41. }
  42. template <typename Protocol, typename Executor1, typename Executor2>
  43. inline ASIO_SYNC_OP_VOID connect_pair(
  44. basic_socket<Protocol, Executor1>& socket1,
  45. basic_socket<Protocol, Executor2>& socket2, asio::error_code& ec)
  46. {
  47. // Check that this function is only being used with a UNIX domain socket.
  48. asio::local::basic_endpoint<Protocol>* tmp
  49. = static_cast<typename Protocol::endpoint*>(0);
  50. (void)tmp;
  51. Protocol protocol;
  52. asio::detail::socket_type sv[2];
  53. if (asio::detail::socket_ops::socketpair(protocol.family(),
  54. protocol.type(), protocol.protocol(), sv, ec)
  55. == asio::detail::socket_error_retval)
  56. ASIO_SYNC_OP_VOID_RETURN(ec);
  57. socket1.assign(protocol, sv[0], ec);
  58. if (ec)
  59. {
  60. asio::error_code temp_ec;
  61. asio::detail::socket_ops::state_type state[2] = { 0, 0 };
  62. asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec);
  63. asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec);
  64. ASIO_SYNC_OP_VOID_RETURN(ec);
  65. }
  66. socket2.assign(protocol, sv[1], ec);
  67. if (ec)
  68. {
  69. asio::error_code temp_ec;
  70. socket1.close(temp_ec);
  71. asio::detail::socket_ops::state_type state = 0;
  72. asio::detail::socket_ops::close(sv[1], state, true, temp_ec);
  73. ASIO_SYNC_OP_VOID_RETURN(ec);
  74. }
  75. ASIO_SYNC_OP_VOID_RETURN(ec);
  76. }
  77. } // namespace local
  78. } // namespace asio
  79. #include "asio/detail/pop_options.hpp"
  80. #endif // defined(ASIO_HAS_LOCAL_SOCKETS)
  81. // || defined(GENERATING_DOCUMENTATION)
  82. #endif // ASIO_LOCAL_CONNECT_PAIR_HPP