当前位置: 首页>>代码示例>>C++>>正文


C++ socket::async_write_some方法代码示例

本文整理汇总了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));
		}
	}
开发者ID:Neoracle,项目名称:socket-session-retainer,代码行数:10,代码来源:session.hpp

示例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();
		}
	}
开发者ID:Neoracle,项目名称:socket-session-retainer,代码行数:15,代码来源:session.hpp

示例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();
}
开发者ID:PauloCaetano,项目名称:SimpleSampleTuts,代码行数:40,代码来源:asyncloop.cpp

示例4: send

	auto send(Func handler, ARGS&...args)
	{
		return s_opt.async_write_some(boost::asio::buffer(args...), handler);
	}
开发者ID:johnzhd,项目名称:boost,代码行数:4,代码来源:boost_net_socket.hpp


注:本文中的boost::asio::ip::tcp::socket::async_write_some方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。