Rewritten PeerConnection::receiveMessage()

The old implementation calls at least 2 read(2) (4bytes length and
payload) to receive the message. This change will read as many bytes
as possible in one read(2) call. BtPieceMessage::data_ is now just a
const pointer to the internal buffer of PeerConnection.
This commit is contained in:
Tatsuhiro Tsujikawa 2012-06-25 21:29:48 +09:00
parent aa34c077cb
commit e816c5eee4
7 changed files with 141 additions and 95 deletions

View file

@ -23,13 +23,13 @@ CPPUNIT_TEST_SUITE_REGISTRATION(PeerConnectionTest);
void PeerConnectionTest::testReserveBuffer() {
PeerConnection con(1, SharedHandle<Peer>(), SharedHandle<SocketCore>());
con.presetBuffer((unsigned char*)"foo", 3);
CPPUNIT_ASSERT_EQUAL((size_t)MAX_PAYLOAD_LEN, con.getMaxPayloadLength());
CPPUNIT_ASSERT_EQUAL((size_t)MAX_BUFFER_CAPACITY, con.getBufferCapacity());
CPPUNIT_ASSERT_EQUAL((size_t)3, con.getBufferLength());
size_t newLength = 32*1024;
con.reserveBuffer(newLength);
CPPUNIT_ASSERT_EQUAL(newLength, con.getMaxPayloadLength());
CPPUNIT_ASSERT_EQUAL(newLength, con.getBufferCapacity());
CPPUNIT_ASSERT_EQUAL((size_t)3, con.getBufferLength());
CPPUNIT_ASSERT(memcmp("foo", con.getBuffer(), 3) == 0);
}