|
Boost Users : |
Subject: [Boost-users] [ASIO] async_read buffer: starting byte null
From: Matty Spatty (mattyspatty_at_[hidden])
Date: 2010-05-23 07:12:35
Hello, I have encountered a problem with some code that I cannot get my head
around, I have spent quite a while looking for solutions but nothing has
come up.
When the client sends the first packet it is read fine but the header(first
8 bytes) for the second packet ALWAYS goes wrong, the first byte in the
buffer is always null and the rest of the packet is pushed down the char
array, e.g.
I have done plenty of checks on the data the client sends:
Client sends 00080002
Header reads _0008000
Client sends 0008TEST
Header reads _0008TES
(with _ as null)
CODE:
This is the first call to async_read, called when the client has connected
-----------------
void CClient::start() {
Log(MSG_INFO, "[%i] Connected", socket_.native());
boost::asio::async_read(socket_,
boost::asio::buffer(packet_.buffer(),
CPacket::headerSize),
boost::bind(&CClient::recvHeader,
shared_from_this(), boost::asio::placeholders::error)
);
}
The rest of the async_read's are called here
-----------------
void CClient::recvMessage(const boost::system::error_code& error) {
if (!error && handleMessage()) {
packet_.reset();
boost::asio::async_read(socket_,
boost::asio::buffer(packet_.buffer(),
CPacket::headerSize),
boost::bind(&CClient::recvHeader,
shared_from_this(), boost::asio::placeholders::error)
);
} else {
disconnect();
}
}
Thanks in adavnce,
Matty.
P.S.
I am very inexperienced with boost and not great at C++ so if you see
anything I could improve, feedback would be appreciated.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net