[Boost-bugs] [asio] I/O Cancellation/completion broken on Linux (x86)

Subject: [Boost-bugs] [asio] I/O Cancellation/completion broken on Linux (x86)
From: Stefan Sichler (stsichler_at_[hidden])
Date: 2008-11-24 17:26:58


Hello,

it seems Asio's I/O cancellation is broken on Linux (x86).
See the small test case below for demonstration. On Windows, the test case
will work correctly, running the loop 10 times. On Linux, it will hang after
the first loop pass.
Further tests revealed that Completion Handlers in general will not be
called reliably even for successful I/Os.

Please help, I urgently need a patch!

(boost 1.37, Debian Linux 2.6.27, Ubuntu Linux 2.6.24)

Regards,
Stefan Sichler

>> code follows:

#ifdef WIN32
#define BOOST_ASIO_ENABLE_CANCELIO
#endif

#include <iostream>
#include <boost/asio.hpp>

using namespace std;
using namespace boost::asio;
using namespace boost::asio::ip;

// boost asio cancellation testcase

bool g_io_completed= false;

void completionHandler(const boost::system::error_code& err, size_t bt) {
        cout<<"completed err="<<err<<" bt="<<bt<<endl;
        g_io_completed= true;
}

int main(int argc, char* argv[])
{
        io_service ios;
        udp::socket sock(ios);
        sock.open(udp::v4());
        sock.bind(udp::endpoint());

        cout<<"note: if this test hangs, the cancel test failed!"<<endl;

        char buf[64];

        for (int i=0; i<10; ++i)
        {
                cout<<"loop start i="<<i<<endl;
                g_io_completed= false;
                sock.async_receive(buffer(buf),completionHandler);

                for (int t=0; t<1000; ++t) // spend some time....
                        ios.poll();

                sock.cancel();

                while (!g_io_completed) // wait for completion handler
                        ios.poll();

                cout<<"loop end i="<<i<<endl;
        }

        cout<<"cancel test completed successfully!"<<endl;

        return 0;
}


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC