How to make asynchronous HTTP request with pion?

380 Views Asked by At

Similar to this question, but I'd like to communicate asynchronously using Pion.

I think I've figured out how to create a connection asynchronously:

pion::tcp::connection_ptr connection(new pion::tcp::connection(_io_service));
connection->async_connect(ep,
                          boost::bind(&http_client::after_connect,
                                      this,
                                      connection,
                                      _1));

Now I'd like to send a request using pion::http::request, but all of its send methods are blocking. How do I send asynchronously?

1

There are 1 best solutions below

0
pmed On

There is a request_writer class in Pion. As I remember it has a send() member function to send data asynchronously.

// create
auto writer = pion::http::request_writer::create(connection);

// set data
writer->write(11);
writer->write(some_buffer, bufer_size);

// send data
writer->send();