本文整理汇总了C++中Endpoint::port方法的典型用法代码示例。如果您正苦于以下问题:C++ Endpoint::port方法的具体用法?C++ Endpoint::port怎么用?C++ Endpoint::port使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Endpoint
的用法示例。
在下文中一共展示了Endpoint::port方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resolve_no_block
void resolve_no_block(
implementation_type & impl,
NetName const & name,
error_code & ec)
{
Endpoint svc;
svc_cache_.find(name, svc, ec);
if (ec) {
impl->ec = ec;
impl->state = ResolveTask::finished;
return;
}
// 可能service只有一种
impl->name = name;
impl->name.protocol((NetName::ProtocolEnum)svc.protocol());
impl->endpoints.clear();
impl->ec.clear();
bool found = host_cache_.find(impl->name, impl->endpoints);
if (found) {
for (size_t i = 0; i < impl->endpoints.size(); ++i) {
impl->endpoints[i].port(svc.port());
}
} else {
ec = boost::asio::error::would_block;
}
#ifndef FRAMEWORK_NETWORK_WITH_SERVICE_CACHE
impl->name.svc(format(svc.port()));
#endif
impl->state = ResolveTask::waiting;
tasks_.push_back(impl);
if (tasks_.size() == 1 && tasks2_.empty()) {
sync_data_->cond.notify_one();
}
}
示例2: 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;
}
示例3: 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();
}
示例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: state
//------------------------------------------------------------------------------
//!
RCP<ConnectedSocketDevice>
Socket::connect( const Endpoint& ep )
{
#if BASE_SOCKET_USE_BSD || BASE_SOCKET_USE_WINSOCK
state( STATE_CONNECTING );
addrinfo* candidates = getAddrInfo( *this, ep.hostname().cstr(), ep.port() );
if( candidates == NULL )
{
return NULL;
}
Family family = fromAPI_family ( candidates->ai_family );
Type type = fromAPI_type ( candidates->ai_socktype );
Protocol protocol = fromAPI_protocol( candidates->ai_protocol );
RCP<Socket> socket = new Socket( family, type, protocol );
int err = ::connect( socket->_impl->_sock, candidates->ai_addr, SocketSSizeT(candidates->ai_addrlen) );
if( err != 0 )
{
printAPIError( "ERROR - Socket::connect() - connect failed" );
freeaddrinfo( candidates );
return NULL;
}
RCP<ConnectedSocketDevice> device = new ConnectedSocketDevice( socket.ptr() );
device->_remoteEndpoint = ep;
freeaddrinfo( candidates );
state( STATE_CONNECTED );
return device;
#else
return NULL;
#endif
}
示例6: deliver
bool DelegateService::deliver(const Endpoint& src, const Endpoint& dst, MemoryReference data) const {
// Check from most to least specific
PortMap const* pm = getPortMap(dst.spaceObject());
if (pm != NULL) {
PortMap::const_iterator it = pm->find(dst.port());
if (it != pm->end())
{
DelegatePort* port = it->second;
bool delivered = port->deliver(src, dst, data);
if (delivered)
return true;
}
}
// And finally, the default handler
if (mDefaultHandler != 0) {
mDefaultHandler(src, dst, data);
return true;
}
return false;
}
示例7: write_endpoint
void write_endpoint(Endpoint const& e, OutIt& out)
{
write_address(e.address(), out);
write_uint16(e.port(), out);
}
示例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());
}
示例9: GetAdjustedTime
ostream& operator<<(ostream& os, const Peer& p) {
/// when NTP implemented, change to just nTime = GetAdjustedTime()
int64_t nTime = (p._inbound ? GetAdjustedTime() : UnixTime::s());
// Endpoint remote = _socket.remote_endpoint();
Endpoint local = p._socket.local_endpoint();
Endpoint addrYou = (p._proxy ? Endpoint("0.0.0.0") : p.addr);
Endpoint addrMe = (p._proxy ? Endpoint("0.0.0.0") : local);
// hack to avoid serializing the time
if (p._version)
os << const_binary<int>(p._version);
else // not initialized - we assume we are sending the version info
os << const_binary<int>(p._chain.protocol_version());
os << const_binary<uint64_t>(NODE_NETWORK) << const_binary<int64_t>(nTime);
os << const_binary<uint64_t>(addrYou.getServices()) << const_binary<boost::asio::ip::address_v6::bytes_type>(addrYou.getIPv6()) << const_binary<unsigned short>(htons(addrYou.port()));
os << const_binary<uint64_t>(addrMe.getServices()) << const_binary<boost::asio::ip::address_v6::bytes_type>(addrMe.getIPv6()) << const_binary<unsigned short>(htons(addrMe.port()));
os << const_binary<uint64_t>(p._nonce) << const_varstr(p._sub_version);
os << const_binary<int>(p._peerManager.getBestHeight());
os << const_binary<bool>(true);
return os;
}