本文整理汇总了C++中endpoint_type类的典型用法代码示例。如果您正苦于以下问题:C++ endpoint_type类的具体用法?C++ endpoint_type怎么用?C++ endpoint_type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了endpoint_type类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bind
bool bind(endpoint_type& endpoint)
{
return socket_ops::bind(
_socket,
endpoint.data(),
endpoint.size());
}
示例2: listen
void listen(endpoint_type const & endpoint, boost::system::error_code & ec, bool reuse_addr = true)
{
if (endpoint.protocol() == protocol_type::v4())
v4_type::listen(endpoint, ec, reuse_addr);
if (endpoint.protocol() == protocol_type::v6())
v6_type::listen(endpoint, ec, reuse_addr);
}
示例3: connect
// Connect the socket to the specified endpoint.
asio::error_code connect(implementation_type& impl,
const endpoint_type& peer_endpoint, asio::error_code& ec)
{
socket_ops::sync_connect(impl.socket_,
peer_endpoint.data(), peer_endpoint.size(), ec);
return ec;
}
示例4: socket
explicit
socket(endpoint_type endpoint) {
typename endpoint_type::protocol_type protocol = endpoint.protocol();
m_fd = ::socket(protocol.family(), protocol.type(), protocol.protocol());
if(m_fd == -1) {
throw std::system_error(errno, std::system_category(), "unable to create a socket");
}
medium_type::configure(m_fd);
if(::connect(m_fd, endpoint.data(), endpoint.size()) != 0) {
auto ec = std::error_code(errno, std::system_category());
::close(m_fd);
throw std::system_error(
ec,
cocaine::format("unable to connect a socket to '%s'", endpoint)
);
}
::fcntl(m_fd, F_SETFD, FD_CLOEXEC);
::fcntl(m_fd, F_SETFL, O_NONBLOCK);
}
示例5: bind
/// Bind the fiber acceptor to the specified local endpoint.
boost::system::error_code bind(implementation_type& impl,
const endpoint_type& endpoint,
boost::system::error_code& ec) {
impl->p_fib_demux = &(endpoint.demux());
impl->p_fib_demux->bind(endpoint.port(), impl, ec);
return ec;
}
示例6: pack
static inline
void
pack(msgpack::packer<Stream>& target, const endpoint_type& source) {
const std::string address = source.address().to_string();
const unsigned short port = source.port();
type_traits<tuple_type>::pack(target, tuple_type(address, port));
}
示例7: send_to
size_t send_to(implementation_type& impl, const ConstBufferSequence& buffers,
const endpoint_type& destination, socket_base::message_flags flags,
asio::error_code& ec)
{
buffer_sequence_adapter<asio::const_buffer,
ConstBufferSequence> bufs(buffers);
return socket_ops::sync_sendto(impl.socket_, impl.state_,
bufs.buffers(), bufs.count(), flags,
destination.data(), destination.size(), ec);
}
示例8: unpack
static inline
void
unpack(const msgpack::object& source, endpoint_type& target) {
std::string address;
unsigned short port;
type_traits<tuple_type>::unpack(source, std::move(std::tie(address, port)));
target.address(boost::asio::ip::address::from_string(address));
target.port(port);
}
示例9: resolve
// Resolve an endpoint to a list of entries.
iterator_type resolve(implementation_type&,
const endpoint_type& endpoint, asio::error_code& ec)
{
char host_name[NI_MAXHOST];
char service_name[NI_MAXSERV];
socket_ops::sync_getnameinfo(endpoint.data(), endpoint.size(),
host_name, NI_MAXHOST, service_name, NI_MAXSERV,
endpoint.protocol().type(), ec);
return ec ? iterator_type() : iterator_type::create(
endpoint, host_name, service_name);
}
示例10: sendto
ssize_t sendto(
endpoint_type& to,
void* buffer,
size_t len
)
{
return detail::socket_ops::sync_sendto(
_socket,
buffer,
len,
0,
to.data(),
to.size());
}
示例11: build_request
virtual request_t build_request(endpoint_type ep, error_code & ec)
{
request_t rc = request_t();
if(!ep.address().is_v4())
{
ec = error_code(boost::asio::error::address_family_not_supported);
return rc;
}
rc.detail.version = 4;
rc.detail.command = 1;
rc.detail.destination_port = ::htons(ep.port());
rc.detail.destination_address = ep.address().to_v4().to_bytes();
rc.detail.end_marker = 0;
return rc;
}
示例12: recvfrom
ssize_t recvfrom(
endpoint_type& from,
void* buffer,
size_t len
)
{
socklen_t size = from.size();
return detail::socket_ops::sync_recvfrom(
_socket,
buffer,
len,
0,
from.data(),
&size);
}
示例13: async_connect
void async_connect(endpoint_type const& endpoint, Handler const& handler)
{
// make sure we don't try to connect to INADDR_ANY. binding is fine,
// and using a hostname is fine on SOCKS version 5.
TORRENT_ASSERT(m_command == socks5_bind
|| endpoint.address() != address()
|| (!m_dst_name.empty() && m_version == 5));
m_remote_endpoint = endpoint;
// the connect is split up in the following steps:
// 1. resolve name of proxy server
// 2. connect to proxy server
// 3. if version == 5:
// 3.1 send SOCKS5 authentication method message
// 3.2 read SOCKS5 authentication response
// 3.3 send username+password
// 4. send SOCKS command message
// to avoid unnecessary copying of the handler,
// store it in a shaed_ptr
boost::shared_ptr<handler_type> h(new handler_type(handler));
ADD_OUTSTANDING_ASYNC("socks5_stream::name_lookup");
tcp::resolver::query q(m_hostname, to_string(m_port).elems);
m_resolver.async_resolve(q, boost::bind(
&socks5_stream::name_lookup, this, _1, _2, h));
}
示例14: async_connect
void async_connect(implementation_type& impl,
const endpoint_type& peer_endpoint, Handler& handler)
{
// Allocate and construct an operation to wrap the handler.
typedef win_iocp_socket_connect_op<Handler> op;
typename op::ptr p = { asio::detail::addressof(handler),
op::ptr::allocate(handler), 0 };
p.p = new (p.v) op(impl.socket_, handler);
ASIO_HANDLER_CREATION((io_context_, *p.p, "socket",
&impl, impl.socket_, "async_connect"));
start_connect_op(impl, impl.protocol_.family(), impl.protocol_.type(),
peer_endpoint.data(), static_cast<int>(peer_endpoint.size()), p.p);
p.v = p.p = 0;
}
示例15: make_error_code
boost::system::error_code
bind
( endpoint_type const& e )
{
// Only fixed port is handled right now.
if ( e.port() != FIXED_PORT )
return make_error_code( boost::system::errc::invalid_argument );
// Generate our local address.
if ( e.address().is_v4() )
local_endpoint( generate_unique_ipv4_endpoint( e.port() ) );
else
local_endpoint( generate_unique_ipv6_endpoint( e.port() ) );
add_route_to_socket( local_endpoint(), this );
return boost::system::error_code();
}