Note that there are some explanatory texts on larger screens.

plurals
  1. POusing boost sockets, do I need only one io_service?
    text
    copied!<p>having several connections in several different threads.. I'm basically doing a base class that uses boost/asio.hpp and the tcp stuff there.. now i was reading this: <a href="http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/tutorial/tutdaytime1.html" rel="noreferrer">http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/tutorial/tutdaytime1.html</a> it says that "All programs that use asio need to have at least one io_service object." so should my base class has a static io_service (which means there will be only 1 for all the program and a all the different threads and connections will use the same io_service object) or make each connection its own io_service?</p> <p>thanks in front!</p> <p>update: OK so basically what I wish to do is a class for a basic client which will have a socket n it. For each socket I'm going to have a thread that always-receives and a different thread that sometimes sends packets. after looking in here: www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/reference/ip__tcp/socket.html (cant make hyperlink since im new here.. so only 1 hyperling per post) I can see that socket class isn't entirely thread-safe..</p> <p>so 2 questions: 1. Based on the design I just wrote, do I need 1 io_service for all the sockets (meaning make it a static class member) or I should have one for each? 2. How can I make it thread-safe to do? should I put it inside a "thread safe environment" meaning making a new socket class that has mutexes and stuff that doesn't let u send and receive at the same time or you have other suggestions? 3. Maybe I should go on a asynch design? (ofc each socket will have a different thread but the sending and receiving would be on the same thread?)</p> <p>just to clarify: im doing a tcp client that connects to a lot of servers.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload