本文整理汇总了C++中Endpoint::address方法的典型用法代码示例。如果您正苦于以下问题:C++ Endpoint::address方法的具体用法?C++ Endpoint::address怎么用?C++ Endpoint::address使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Endpoint
的用法示例。
在下文中一共展示了Endpoint::address方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool operator<(const Endpoint& a, const Endpoint& b)
{
int ret = memcmp(a._ipv6, b._ipv6, sizeof(a._ipv6));
if (ret < 0)
return true;
else if (ret == 0)
{
if (ntohl(a.address().to_v4().to_ulong()) < ntohl(b.address().to_v4().to_ulong()))
return true;
else if (a.address() == b.address())
return ntohs(a.port()) < ntohs(b.port());
}
return false;
}
示例2: close
void SaslConnection::close()
{
Endpoint client = peer();
Connection::close();
if ( !u || logged ||
!client.valid() || client.protocol() == Endpoint::Unix )
return;
logged = true;
Query * q = new Query(
"insert into connections "
"(username,address,port,mechanism,authfailures,"
"syntaxerrors,started_at,ended_at,userid) "
"values ($1,$2,$3,$4,$5,$6,"
"$7::interval + 'epoch'::timestamptz,"
"$8::interval + 'epoch'::timestamptz,$9)", 0
);
q->bind( 1, u->login() );
q->bind( 2, client.address() );
q->bind( 3, client.port() );
q->bind( 4, m );
q->bind( 5, af );
q->bind( 6, sf );
q->bind( 7, s );
q->bind( 8, (uint)time( 0 ) );
q->bind( 9, u->id() );
q->execute();
}
示例3: bind
int bind(descriptor const& desc, Endpoint const& endpoint)
{
error_code ec;
system::call(::bind, desc.c_descriptor(),
static_cast<sockaddr const*>(endpoint.address().first),
endpoint.address().second,
ec,
-1
);
if(ec)
{
report_error re;
return re("socket::bind", ec);
}
return error_code::success;
}
示例4: listen
int Connection::listen( const Endpoint &e, bool silent )
{
if ( !e.valid() )
return -1;
if ( !valid() ) {
init( socket( e.protocol() ) );
if ( !valid() )
return -1;
}
int i = 1;
::setsockopt( d->fd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (int) );
if ( e.protocol() == Endpoint::Unix )
unlink( File::chrooted( e.address() ).cstr() );
int retcode = ::bind( d->fd, e.sockaddr(), e.sockaddrSize() );
if ( retcode < 0 ) {
if ( errno == EADDRINUSE ) {
if ( !silent )
log( "Cannot listen to " +
e.address() + " port " + fn( e.port() ) +
" because another process is occupying it", Log::Error );
return -1;
}
if ( !silent )
log( "bind( " + fn( d->fd ) + ", " +
e.address() + " port " + fn( e.port() ) +
" ) returned errno " + fn( errno ), Log::Debug );
return -1;
}
if ( ::listen( d->fd, 64 ) < 0 ) {
if ( !silent )
log( "listen( " + fn( d->fd ) + ", 64 ) for address " +
e.address() + " port " + fn( e.port() ) +
" ) returned errno " + fn( errno ), Log::Debug );
return -1;
}
setState( Listening );
d->self = e;
return 1;
}
示例5: send_to
std::size_t send_to(descriptor const& desc, mutable_buffer_container buffer, Endpoint const& endpoint)
{
error_code ec;
std::size_t ret;
ret = system::call(::sendto, desc.c_descriptor(),
buffer_cast<char const*>(buffer),
buffer_size(buffer),
0,
static_cast<sockaddr const*>(endpoint.address().first),
endpoint.address().second,
ec,
-1
);
if(ec)
{
report_error re;
return re("socket::send_to", ec);
}
return ret;
}
示例6: write_endpoint
void write_endpoint(Endpoint const& e, OutIt& out)
{
write_address(e.address(), out);
write_uint16(e.port(), out);
}
示例7: testEndpoint
void testEndpoint ()
{
testcase ("Endpoint");
{
std::pair <Endpoint, bool> result (
Endpoint::from_string_checked ("1.2.3.4"));
expect (result.second);
if (expect (result.first.address().is_v4 ()))
{
expect (result.first.address().to_v4() ==
AddressV4 (1, 2, 3, 4));
expect (result.first.port() == 0);
expect (to_string (result.first) == "1.2.3.4");
}
}
{
std::pair <Endpoint, bool> result (
Endpoint::from_string_checked ("1.2.3.4:5"));
expect (result.second);
if (expect (result.first.address().is_v4 ()))
{
expect (result.first.address().to_v4() ==
AddressV4 (1, 2, 3, 4));
expect (result.first.port() == 5);
expect (to_string (result.first) == "1.2.3.4:5");
}
}
Endpoint ep;
ep = Endpoint (AddressV4 (127,0,0,1), 80);
expect (! is_unspecified (ep));
expect (! is_public (ep));
expect ( is_private (ep));
expect (! is_multicast (ep));
expect ( is_loopback (ep));
expect (to_string (ep) == "127.0.0.1:80");
ep = Endpoint (AddressV4 (10,0,0,1));
expect (AddressV4::get_class (ep.to_v4()) == 'A');
expect (! is_unspecified (ep));
expect (! is_public (ep));
expect ( is_private (ep));
expect (! is_multicast (ep));
expect (! is_loopback (ep));
expect (to_string (ep) == "10.0.0.1");
ep = Endpoint (AddressV4 (166,78,151,147));
expect (! is_unspecified (ep));
expect ( is_public (ep));
expect (! is_private (ep));
expect (! is_multicast (ep));
expect (! is_loopback (ep));
expect (to_string (ep) == "166.78.151.147");
{
ep = Endpoint::from_string ("192.0.2.112");
expect (! is_unspecified (ep));
expect (ep == Endpoint::from_string_altform ("192.0.2.112"));
auto const ep1 = Endpoint::from_string ("192.0.2.112:2016");
expect (! is_unspecified (ep1));
expect (ep.address() == ep1.address());
expect (ep1.port() == 2016);
auto const ep2 =
Endpoint::from_string_altform ("192.0.2.112:2016");
expect (! is_unspecified (ep2));
expect (ep.address() == ep2.address());
expect (ep2.port() == 2016);
expect (ep1 == ep2);
auto const ep3 =
Endpoint::from_string_altform ("192.0.2.112 2016");
expect (! is_unspecified (ep3));
expect (ep.address() == ep3.address());
expect (ep3.port() == 2016);
expect (ep2 == ep3);
auto const ep4 =
Endpoint::from_string_altform ("192.0.2.112 2016");
expect (! is_unspecified (ep4));
expect (ep.address() == ep4.address());
expect (ep4.port() == 2016);
expect (ep3 == ep4);
expect (to_string(ep1) == to_string(ep2));
expect (to_string(ep1) == to_string(ep3));
expect (to_string(ep1) == to_string(ep4));
}
// Failures:
expect (is_unspecified (
Endpoint::from_string ("192.0.2.112:port")));
expect (is_unspecified (
Endpoint::from_string_altform ("192.0.2.112:port")));
expect (is_unspecified (
Endpoint::from_string_altform ("192.0.2.112 port")));
//.........这里部分代码省略.........
示例8: return
bool operator==(const Endpoint& a, const Endpoint& b)
{
return (memcmp(a._ipv6, b._ipv6, sizeof(a._ipv6)) == 0 &&
a.address() == b.address() &&
a.port() == b.port());
}