本文整理汇总了C++中boost::asio::ip::tcp::socket::get_io_service方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::get_io_service方法的具体用法?C++ socket::get_io_service怎么用?C++ socket::get_io_service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::tcp::socket
的用法示例。
在下文中一共展示了socket::get_io_service方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AsyncLoopSocket
void AsyncLoopSocket(boost::function<TaskState()> doWork, boost::asio::ip::tcp::socket& sock, bool isRead)
{
if (sock.get_io_service().stopped())
{
return;
}
TaskState st = doWork();
if (st == TASK_WORKING)
{
if (isRead)
{
sock.async_read_some(boost::asio::null_buffers(), bind(AsyncLoopSocket, doWork, boost::ref(sock),
isRead));
}
else
{
sock.async_write_some(boost::asio::null_buffers(), bind(AsyncLoopSocket, doWork, boost::ref(sock),
isRead));
}
return;
}
// Work is over. stop any outstanding events.
// NOTE: this isn't 100% reliable, and there may be events that linger in the queue.
// The next time we reset() and run() the io_service, these events will be processed,
// and io_service::stopped() will return false, because we've just done reset() and run().
// The state management (SSHSession::State) is our first step in controlling this, and we
// may need to implement our own cancel mechanism
//
// this io_service feature poses an additional problem - by spreading the implementation
// responsibility across multiple classes, we create scenarios where io_service's queue
// may contain outstanding events referring to objects that were, in the meantime, destroyed.
// this is why we're favouring, for now, the use of AsyncLoopTimer, where we can use an
// io_service for each timer, and destroy it right after being used. this makes sure we
// process no "zombie" outstanding events.
sock.get_io_service().stop();
}
示例2: memset
connection::connection(boost::asio::ip::tcp::socket socket,
connection_manager& manager/*, request_handler& handler*/)
: strand_(socket.get_io_service()),
socket_(std::move(socket)),
connection_manager_(manager),
request_handler_(*this),
total_bytes_received_(0),
timestamp_(0)
{
request_.header_length = 0;
request_.content_length = 0;
memset(this->v4_address_, 0x0, sizeof(this->v4_address_));
//tid_ = this_thread();
//LOG_TRACE_ALL("construct a connection resource ok, thread id:%u", tid_);
}