Dro*_*rii 2 c++ networking boost asynchronous boost-asio
当我调用 async_write 2 次时,第二条消息不会发送到服务器。在写入处理程序中,我调用 async_read 并且当我运行我的代码时,程序卡在读取状态。在连接处理程序中:
clientSocketPtr->lowest_layer().set_option(BA::ip::tcp::no_delay(true));
clientSocketPtr->set_verify_mode(BA::ssl::verify_peer);
clientSocketPtr->set_verify_callback(BA::ssl::host_name_verification(ADDRESS));
clientSocketPtr->handshake(ssl_socket::client);
//first call with first message(76 bytes)
BA::post(io_context, boost::bind(&ssd::write_msg, message, clientSocketPtr));
//some code here
//second call with another message(160 bytes)
BA::post(io_context, boost::bind(&ssd::write_msg, message, clientSocketPtr));
Run Code Online (Sandbox Code Playgroud)
在 write_msg 中:
void ssd::write_msg(ssd::Message &msg, ssd::ssl_socket *clientSocketPtr) {
//some code here
BA::async_write(*clientSocketPtr, BA::buffer(buf, bufSize), BA::transfer_exactly(bufSize), boost::bind(&ssd::write_handler,
BA::placeholders::error, BA::placeholders::bytes_transferred, clientSocketPtr));
io_context.run();
}
Run Code Online (Sandbox Code Playgroud)
在写处理程序中,我调用:
BA::post(io_context, boost::bind(&ssd::read_msg, clientSocketPtr));
Run Code Online (Sandbox Code Playgroud)
在 read_msg 中,我调用 async_read。
输出为文本:
I20200818 11:17:38.633821 7417 message.hpp:53]
Message type: 1
Message length: 70
Message: {"cli_type":"tarball","cli_version":"v2020.07.18","cmd":"cli_version"}
I20200818 11:17:38.637073 7417 sslconnection.cpp:77] Bytes sent: 76
I20200818 11:17:38.637115 7417 sslconnection.cpp:77] Bytes sent: 160
I20200818 11:17:38.640669 7417 sslconnection.cpp:109] Bytes recieved: 6
I20200818 11:17:38.640744 7417 sslconnection.cpp:122] Bytes recieved: 47
I20200818 11:17:38.640764 7417 sslconnection.cpp:128]
Message length: 47
Message: {"cmd":"be_version","be_version":"v2020.07.15"}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
81 次 |
最近记录: |