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


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

本文整理汇总了C++中tcp::socket::async_read_some方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::async_read_some方法的具体用法?C++ socket::async_read_some怎么用?C++ socket::async_read_some使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcp::socket的用法示例。


在下文中一共展示了socket::async_read_some方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: echo

awaitable<void> echo(tcp::socket s)
{
 auto token = co_await this_coro::token();

 try
 {
   char data1[1024];
   char data2[1024];

   char* p1 = data1;
   char* p2 = data2;

   // Perform initial read into first buffer.
   size_t n = co_await s.async_read_some(boost::asio::buffer(p1, 1024), token);

   for (;;)
   {
     // Swap received data to other buffer and initiate write operation.
     std::swap(p1, p2);
     auto write_result = boost::asio::async_write(s, boost::asio::buffer(p2, n), token);

     // Perform next read while write operation is in progress.
     n = co_await s.async_read_some(boost::asio::buffer(p1, 1024), token);

     // Wait for write operation to complete before proceeding.
     co_await write_result;
   }
 }
 catch (std::exception& e)
 {
   std::printf("echo Exception: %s\n", e.what());
 }
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:33,代码来源:double_buffered_echo_server.cpp

示例2: start

 void start()
 {
     fprintf(stderr, "session::handle_read()\n");
     socket_.async_read_some(boost::asio::buffer(data_, max_length),
             boost::bind(&session::handle_read, this,
                 boost::asio::placeholders::error,
                 boost::asio::placeholders::bytes_transferred));
 }
开发者ID:mw-ding,项目名称:DMW-Chat,代码行数:8,代码来源:echo_server.cpp

示例3: read_handler

void read_handler(const boost::system::error_code &ec,
                  std::size_t bytes_transferred)
{
    if (!ec)
    {
        std::cout.write(bytes.data(), bytes_transferred);
        tcp_socket.async_read_some(buffer(bytes), read_handler);
    }
}
开发者ID:stormogulen,项目名称:misc-code-snippets,代码行数:9,代码来源:web_client.cpp

示例4: connect_handler

void connect_handler(const boost::system::error_code &ec)
{
    if (!ec)
    {
        std::string r =
            "GET / HTTP/1.1\r\nHost: theboostcpplibraries.com\r\n\r\n";
        write(tcp_socket, buffer(r));
        tcp_socket.async_read_some(buffer(bytes), read_handler);
    }
}
开发者ID:stormogulen,项目名称:misc-code-snippets,代码行数:10,代码来源:web_client.cpp

示例5: handle_write

 void handle_write(const boost::system::error_code &error)
 {
     fprintf(stderr, "session::handle_write()\n");
     if (!error)
     {
         socket_.async_read_some(boost::asio::buffer(data_, max_length),
                 boost::bind(&session::handle_read, this,
                     boost::asio::placeholders::error,
                     boost::asio::placeholders::bytes_transferred));
     }
     else
     {
         delete this;
     }
 }
开发者ID:mw-ding,项目名称:DMW-Chat,代码行数:15,代码来源:echo_server.cpp

示例6: f

	void f() {
		auto p(shared_from_this());
		using namespace std;
		cout << "fuck" << endl;
		//_socket.open(tcp::v4());
		_socket.async_read_some(asio::buffer(reply, 100),
			[p, this](std::error_code ec, std::size_t len) {
				using namespace std;
				cout << ec << " " << len << endl;
				std::cout.write(reply, len);
		});
		/*asio::async_read(_socket, asio::buffer(reply, 10240), [this, p](std::error_code ec, std::size_t len) {
			using namespace std;
			cout << ec << " " << len << endl;
		});*/

		/*int len = asio::read(_socket, asio::buffer(reply, 10));
    	std::cout.write(reply, len);*/
	}
开发者ID:kaitian521,项目名称:boost_learn,代码行数:19,代码来源:client.cpp

示例7: handle_write

 void handle_write() {
         socket_.async_read_some(boost::asio::buffer(data_, max_length),
                                 bind(&session::handle_read, this,
                                      boost::asio::placeholders::error,
                                      boost::asio::placeholders::bytes_transferred));
 }
开发者ID:nikitaband1t,项目名称:finalProject,代码行数:6,代码来源:main.cpp


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