Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exacty is io_context?

I have been going throught the boost asio library in which most of the objects need the io_context object as argument to the constructor. I have read what io_context object,according to the documentation it states that it is

The io_context class provides the core I/O functionality for users of the asynchronous I/O objects

Which confuses me because isn't that what iostream does.I'm really sure i'm missing something,please help me clarify it and also i don't see much difference between I/O objects with the sockets other than fact that sockets can be used for exchanging data between two devices whereas I/O objects enable us to exchange data with our computer.I'm really confused at this point!

like image 847
Bad_Panda Avatar asked Apr 02 '20 17:04

Bad_Panda


People also ask

What is Io_context?

The io_context class provides the core I/O functionality for users of the asynchronous I/O objects, including: boost::asio::ip::tcp::socket. boost::asio::ip::tcp::acceptor. boost::asio::ip::udp::socket. deadline_timer .

What is boost beast?

Loading. This item will be sent to your system automatically after purchase. "BOOST BEAST" is a defense puzzle game where players defeat the invading horde of zombies by clearing blocks and summoning animals.

What is asio boost?

Boost. Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach. Overview. An overview of the features included in Boost. Asio, plus rationale and design information.

What is boost asio post?

boost::asio::post posts a given functor into the execution queue and that functor is executed along with other functors and completion handlers in a general way. The function is thread-safe so feel free to post from different threads.


1 Answers

io_context contains state required to run the event loop based on select, epoll, or other platform-specific calls and dispatch events, such as socket readiness, timer, signal, idle, to the callbacks the user has registered. Many callbacks for different sockets, timers, etc.. can be registered with one io_context. io_context doesn't do I/O, but it invokes those callbacks when I/O can be done in non-blocking fashion, e.g. data has arrived and the socket is ready for read, and the callback does the actual non-blocking I/O.

See Basic Boost.Asio Anatomy for more details.

Other popular event loops are libevent and libuv

The C10K problem is old but quite instructive on the subject of async I/O.


C++20 coroutines introduce a new programming model, which has benefits of being simpler to write and read and it mitigates callback hell inherent in non-blocking I/O code. Boost.Asio supports coroutines.

like image 184
Maxim Egorushkin Avatar answered Oct 25 '22 16:10

Maxim Egorushkin