本文整理汇总了C++中Address::getSockaddr方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::getSockaddr方法的具体用法?C++ Address::getSockaddr怎么用?C++ Address::getSockaddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::getSockaddr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw
SOCKET
SocketBase::doAccept(Address& fromaddr) throw(NetworkException)
{
if ( state == LISTENING )
{
SOCKET newsock;
newsock= accept(sockfd, fromaddr.getSockaddr(), fromaddr.getSockaddrLenPointer());
if ( newsock == INVALID_SOCKET )
{
lastError = GET_NET_ERROR();
if ( ! IS_ACCEPT_IGNORABLE(lastError) )
{
std::stringstream msg;
msg << "Accept error: " << NETSTRERROR(lastError);
LOGGER.warning("%s", msg.str().c_str());
}
}
return newsock;
}
else
{
LOGGER.warning("Trying to accept on an unlistening socket [%s]", getStateString());
}
return SOCKET_ERROR;
}
示例2: NetworkException
void
SocketBase::bindSocketTo(const Address& toaddr) throw(NetworkException)
{
if ( state == CONFIGURED )
{
int res = bind(sockfd, toaddr.getSockaddr(), toaddr.getSockaddrLen());
if(res == SOCKET_ERROR) {
lastError = GET_NET_ERROR();
doClose();
std::stringstream msg;
msg << "Couldn't bind socket to address '"
<< toaddr.getIP() << "' port " << toaddr.getPort()
<< ": " << NETSTRERROR(lastError);
throw NetworkException(msg.str());
}
SocketManager::addSocket(this);
state = BOUND;
}
else
{
LOGGER.warning("Trying to bind to a socket != CONFIGURED [%s]", getStateString());
}
}