Boost logo

Boost Users :

Subject: Re: [Boost-users] async accept asio thread error
From: Gianni Ambrosio (gianni.ambrosio_at_[hidden])
Date: 2011-04-06 05:20:58


Il 4/6/2011 10:03 AM, Igor R ha scritto:
>> No, I'm sorry I forgot one line at the end:
>>
>> thread = boost::thread(boost::bind(&boost::asio::io_service::run,
>> &io_service));
> Ok, but this line just creates a thread and passes to it
> io_service::run() -- it doesn't block your current thread, where you
> issued async_accept.
> Ensure that the thread where you *call* async_accept() doesn't ends
> before the operation is complete.

Igor, thanks for your patience.

You are right, the piece of code I posted does not block the thread. May
be it's better going back to the test I posted at first:

    Server server;
    server.acceptAsyncOnThread(port);

    Client client;
    TcpSessionPtr connection = client.connect(host, port);

    bool accepted = false;
    boost::timer timer;
    while (!accepted && timer.elapsed() < 1.0)
    {
       accepted = server.accepted();
    }

Here the Server class derives from TcpSocket and the
acceptAsyncOnThread() basically calls the code I posted in the prevoius
email including the thread. The server.accepted() returns true if the
callback of the accept_async is called (and it works correctly indeed).
The process is blocked by a loop with a timer (as you can see from the
code). I would be glad if you could find the error in that code.

Regards
Gianni


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