Boost logo

Boost :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-12-27 22:50:12


--- "Victor A. Wagner Jr." <vawjr_at_[hidden]> wrote:
> you may be pleased to know that with the
> "release" vs2005 there is no assert (debug), but
> I'm concerned about the program itself.
> I get different outputs from release and debug
> release:
> Successful accept
> Successful connect
> Successful receive
> hello therePress any key to continue . . .
> .....long pause before the last line.
>
> debug:
> Successful accept
> Successful connect
> Successful receive
> hello
> there¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
<snip>

It's a very easy to fix bug in the test program :)

As you said, handle_recv currently assumes the buffer is
NUL-terminated, when in fact it isn't. It would be better written
as:

  void handle_accept(const error& err)
  {
    ...
      socket_.async_read_some(buffer(buf_, sizeof(buf_)),
          boost::bind(&stream_handler::handle_recv, this,
            boost::asio::placeholders::error,
            boost::asio::placeholders::bytes_transferred));
    ...
  }

  void handle_recv(const error& err, size_t bytes_transferred)
  {
    if (err)
    {
      std::cout << "Receive error: " << err << "\n";
    }
    else
    {
      std::cout << "Successful receive\n";
      std::cout.write(buf_, bytes_transferred);
    }
  }

Cheers,
Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk