inline boost::system::error_code connect_pair(
    basic_socket<Protocol, SocketService1>& socket1,
    basic_socket<Protocol, SocketService2>& socket2,
    boost::system::error_code& ec)
{
  // Check that this function is only being used with a UNIX domain socket.
  boost::asio::local::basic_endpoint<Protocol>* tmp
    = static_cast<typename Protocol::endpoint*>(0);
  (void)tmp;

  Protocol protocol;
  boost::asio::detail::socket_type sv[2];
  if (boost::asio::detail::socket_ops::socketpair(protocol.family(),
        protocol.type(), protocol.protocol(), sv, ec)
      == boost::asio::detail::socket_error_retval)
    return ec;

  if (socket1.assign(protocol, sv[0], ec))
  {
    boost::system::error_code temp_ec;
    boost::asio::detail::socket_ops::close(sv[0], temp_ec);
    boost::asio::detail::socket_ops::close(sv[1], temp_ec);
    return ec;
  }

  if (socket2.assign(protocol, sv[1], ec))
  {
    boost::system::error_code temp_ec;
    socket1.close(temp_ec);
    boost::asio::detail::socket_ops::close(sv[1], temp_ec);
    return ec;
  }

  return ec;
}
Exemplo n.º 2
0
		bool open(const Protocol& protocol)
		{
			_socket = socket_ops::socket(
				protocol.family(),
				protocol.type(),
				protocol.protocol()
			);
			return _socket != invalid_socket;
		}
Exemplo n.º 3
0
 stream_protocol( const Protocol& source_protocol )
     : family_( source_protocol.family( ) ), protocol_( source_protocol.protocol( ) )
 {
     if ( source_protocol.type( ) != type( ) )
     {
         std::bad_cast ex;
         asio::detail::throw_exception( ex );
     }
 }
 seq_packet_protocol(const Protocol& source_protocol)
   : family_(source_protocol.family()),
     protocol_(source_protocol.protocol())
 {
   if (source_protocol.type() != type())
   {
     std::bad_cast ex;
     lslboost::asio::detail::throw_exception(ex);
   }
 }
Exemplo n.º 5
0
inline BOOST_ASIO_SYNC_OP_VOID connect_pair(
    basic_socket<Protocol BOOST_ASIO_SVC_TARG>& socket1,
    basic_socket<Protocol BOOST_ASIO_SVC_TARG1>& socket2,
    boost::system::error_code& ec)
{
  // Check that this function is only being used with a UNIX domain socket.
  boost::asio::local::basic_endpoint<Protocol>* tmp
    = static_cast<typename Protocol::endpoint*>(0);
  (void)tmp;

  Protocol protocol;
  boost::asio::detail::socket_type sv[2];
  if (boost::asio::detail::socket_ops::socketpair(protocol.family(),
        protocol.type(), protocol.protocol(), sv, ec)
      == boost::asio::detail::socket_error_retval)
    BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);

  socket1.assign(protocol, sv[0], ec);
  if (ec)
  {
    boost::system::error_code temp_ec;
    boost::asio::detail::socket_ops::state_type state[2] = { 0, 0 };
    boost::asio::detail::socket_ops::close(sv[0], state[0], true, temp_ec);
    boost::asio::detail::socket_ops::close(sv[1], state[1], true, temp_ec);
    BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  }

  socket2.assign(protocol, sv[1], ec);
  if (ec)
  {
    boost::system::error_code temp_ec;
    socket1.close(temp_ec);
    boost::asio::detail::socket_ops::state_type state = 0;
    boost::asio::detail::socket_ops::close(sv[1], state, true, temp_ec);
    BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
  }

  BOOST_ASIO_SYNC_OP_VOID_RETURN(ec);
}