[Boost-bugs] [Boost C++ Libraries] #9794: Calling async_read_some before(tcp::socket, ...) before tcp::socket::async_connect handler is called causes async_connect handler to indicate successful connect

Subject: [Boost-bugs] [Boost C++ Libraries] #9794: Calling async_read_some before(tcp::socket, ...) before tcp::socket::async_connect handler is called causes async_connect handler to indicate successful connect
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-03-20 04:56:44


#9794: Calling async_read_some before(tcp::socket, ...) before
tcp::socket::async_connect handler is called causes async_connect handler
to indicate successful connect
------------------------------+----------------------------
 Reporter: tim.pavlic@… | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.55.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------------
 Given the example in this ticket, and assuming that there is no service
 running on localhost:29873, I would expect the example to print:
 {{{
 Failed to read
 Failed to connect
 }}}
 Instead I get:
 {{{
 Failed to read
 Connected!
 }}}


 {{{
 #!cpp
 #include <iostream>
 #include <istream>
 #include <ostream>
 #include <string>
 #include <boost/asio.hpp>
 #include <boost/bind.hpp>

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

 int main(int argc, char* argv[])
 {
     asio::io_service ios;
     tcp::socket socket{ios};

     tcp::endpoint endpoint(asio::ip::address::from_string("127.0.0.1"),
 29873);

     socket.async_connect(endpoint, [](const system::error_code& ec) {
         if ( !ec ) {
             cout << "Connected!" << endl;
         } else {
             cout << "Failed to connect" << endl;
         }
     });

     asio::streambuf readBuffer;
     asio::async_read_until(socket, readBuffer, '\n', [](const
 system::error_code& ec, size_t size) {
         if ( !ec ) {
             cout << "Read " << size << " " << endl;
         } else {
             cout << "Failed to read" << endl;
         }
     });

     ios.run();
 }
 }}}

 I also have the same problem in boost 1.48.

 I know it's not really logical to do what the example shows, but I would
 not expect the result it gives.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9794>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC