|
Boost Users : |
Subject: Re: [Boost-users] [boost-users][asio] timeout - isio_service.reset() safe with pool of threads?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-02-02 04:08:05
>
> You know, io_service must be run for accepting.
>
Again - io_service must be running for *asynchronous* accepting
(async_accept), but if you use syncronous accept() then you never explicitly
run io_service. See the following example:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/echo/blocking_tcp_echo_server.cpp
> don't we have to do it in such way?
>
> acceptor_(io_service_)
> acceptor_.bind
> acceptor_.listen
> acceptor_.async_accept
> io_service_.run
>
You mixed here blocking and asyncronous calls (which is
legitimate), and since asyncronous calls present in your code someone must
process them - that's exactly what io_service::run does, and that's why you
must call io_service_run() (please note that io_service.run() is blocking
call, meaning that it wouldn't return before all pending work is done). But
if you would stick with blocking calls only, you wouldn't have to run
io_service:
acceptor_(io_service_)
acceptor_.bind
acceptor_.listen
acceptor_.accept // not async_accept!
// do something with the accepted socket...
>> Note that it is an async. implementation for *synchronous* use, and when
you use sync. i/o you do not explicitly run io_service:
>> io_service io;
>> tcp::socket sock(io);
>> // open socket, define your buffer..., then:
>> read_with_timeout(sock, buffer);
> I don't understend. what is synchronous here? could You explain Igor?
"Synchronous" (or blocking) means that a function call completes ("returns")
only after its job is done. In our case read_with_timeout blocks until the
data is read or the timeout occurs. Asynchronous version would return
immediately, and when the desired event occurs, it would notify you by means
of the completion handler that you supply.
>> But if you've already got an async. design, you don't need workarounds to
implement timeouts - just use deadline_timer in the straightforward way.
> it's mean - how? which example shows it?
Please, look at this exmaple (it's very simple and demonstrates exactly what
you need):
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/timeouts/accept_timeout.cpp
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