Boost logo

Boost Users :

Subject: Re: [Boost-users] Asio::Async_read_some - bytes_transferred=0!
From: Igor R (boost.lists_at_[hidden])
Date: 2010-06-28 07:21:13


> What surprises me here is -
>
> *) The socket is not closed
> *) The accept handler of initial async_read_some gets the error ("The I/O
> operation has been aborted because of either a thread exit or an application
> request")
>
> *) After that I am able to wait on same socket and read the data from
> socket. (The async_read_some is again called form the handler of the
> "initial async_read_some 's accept handler in a recursive manner)
>
> Could there be any other reason for this? This is a multi-threaded
> application and each socket is created in a new thread, and thread would not
> exit without completing its execution...

Maybe the thread that calls async_read exits before the relevant
completion handler is invoked?

By the way, using threads in the way you described in asio-based
program is usually a bad idea. The whole point of using async i/o is
to avoid such an "explicit" multithreading -- usually one spawns
multiple threads to scale for multiple CPUs only.
http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_3
http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html#boost_asio.examples.http_server_2


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net