Boost ASIO async_write "Vector iterator not dereferencable"

Posted by xeross on Stack Overflow See other posts from Stack Overflow or by xeross
Published on 2010-04-30T21:45:09Z Indexed on 2010/04/30 21:47 UTC
Read the original article Hit count: 269

Filed under:
|
|

Hey,

I've been working on an async boost server program, and so far I've got it to connect. However I'm now getting a "Vector iterator not dereferencable" error.

I suspect the vector gets destroyed or dereferenced before he packet gets sent thus causing the error.

void start()
{
    Packet packet;
    packet.setOpcode(SMSG_PING);
    send(packet);
}

void send(Packet packet)
{
    cout << "DEBUG> Transferring packet with opcode " << packet.GetOpcode() << endl;
    async_write(m_socket, buffer(packet.write()), boost::bind(&Session::writeHandler, shared_from_this(), placeholders::error, placeholders::bytes_transferred));
}

void writeHandler(const boost::system::error_code& errorCode, size_t bytesTransferred)
{
    cout << "DEBUG> Transfered " << bytesTransferred << " bytes to " << m_socket.remote_endpoint().address().to_string() << endl;
}

Start gets called once a connection is made. packet.write() returns a uint8_t vector

Would it matter if I'd change

void send(Packet packet)

to

void send(Packet& packet)

Not in relation to this problem but performance wise.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost