本文整理汇总了C++中SocketPtr::getInetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ SocketPtr::getInetAddress方法的具体用法?C++ SocketPtr::getInetAddress怎么用?C++ SocketPtr::getInetAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketPtr
的用法示例。
在下文中一共展示了SocketPtr::getInetAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sync
void* APR_THREAD_FUNC SocketHubAppender::monitor(apr_thread_t* /* thread */, void* data) {
SocketHubAppender* pThis = (SocketHubAppender*) data;
ServerSocket* serverSocket = 0;
try
{
serverSocket = new ServerSocket(pThis->port);
serverSocket->setSoTimeout(1000);
}
catch (SocketException& e)
{
LogLog::error(LOG4CXX_STR("exception setting timeout, shutting down server socket."), e);
delete serverSocket;
return NULL;
}
bool stopRunning = pThis->closed;
while (!stopRunning)
{
SocketPtr socket;
try
{
socket = serverSocket->accept();
}
catch (InterruptedIOException&)
{
// timeout occurred, so just loop
}
catch (SocketException& e)
{
LogLog::error(LOG4CXX_STR("exception accepting socket, shutting down server socket."), e);
stopRunning = true;
}
catch (IOException& e)
{
LogLog::error(LOG4CXX_STR("exception accepting socket."), e);
}
// if there was a socket accepted
if (socket != 0)
{
try
{
InetAddressPtr remoteAddress = socket->getInetAddress();
LogLog::debug(LOG4CXX_STR("accepting connection from ")
+ remoteAddress->getHostName()
+ LOG4CXX_STR(" (")
+ remoteAddress->getHostAddress()
+ LOG4CXX_STR(")"));
// add it to the oosList.
synchronized sync(pThis->mutex);
OutputStreamPtr os(new SocketOutputStream(socket));
Pool p;
ObjectOutputStreamPtr oos(new ObjectOutputStream(os, p));
pThis->streams.push_back(oos);
}
catch (IOException& e)
{
LogLog::error(LOG4CXX_STR("exception creating output stream on socket."), e);
}
}
stopRunning = (stopRunning || pThis->closed);
}
delete serverSocket;
return NULL;
}