本文整理汇总了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());
}
}
示例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));
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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);*/
}
示例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));
}