Boost ASIO async_write "Vector iterator not dereferencable"
- by xeross
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.