本文整理汇总了C++中boost::asio::ip::tcp::socket::async_write_some方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::async_write_some方法的具体用法?C++ socket::async_write_some怎么用?C++ socket::async_write_some使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::ip::tcp::socket
的用法示例。
在下文中一共展示了socket::async_write_some方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send
virtual void send(raw_data& data) {
bool write_in_progress = !buffer_write_queue_.empty();
buffer_write_queue_.push_back(data);
if (!write_in_progress) {
socket_.async_write_some(
boost::asio::buffer(buffer_write_queue_.front().bytes, buffer_write_queue_.front().length),
boost::bind(&session::handle_write, shared_from_this(),
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
}
示例2: handle_write
void handle_write(const boost::system::error_code& error, std::size_t bytes_transferred) {
if (!error) {
buffer_write_queue_.pop_front();
if (!buffer_write_queue_.empty()) {
socket_.async_write_some(
boost::asio::buffer(buffer_write_queue_.front().bytes, buffer_write_queue_.front().length),
boost::bind(&session::handle_write, shared_from_this(),
boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
}
}
else {
std::cout << "error in writing data" << std::endl;
this->onError();
}
}
示例3: 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();
}
示例4: send
auto send(Func handler, ARGS&...args)
{
return s_opt.async_write_some(boost::asio::buffer(args...), handler);
}