2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Returns cached data without checking whether socket is readable
	if the cache is available.
	* src/PeerConnection.cc (receiveHandshake)
This commit is contained in:
Tatsuhiro Tsujikawa 2008-06-08 10:16:38 +00:00
parent 5cbab84b65
commit 249194ba8d
2 changed files with 31 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2008-06-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Returns cached data without checking whether socket is readable
if the cache is available.
* src/PeerConnection.cc (receiveHandshake)
2008-06-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Included stdint.h

View File

@ -130,12 +130,20 @@ bool PeerConnection::receiveMessage(unsigned char* data, size_t& dataLength) {
bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
bool peek) {
bool retval = true;
if(!peek && resbufLength) {
// We have data in previous peek.
// There is a chance that socket is readable because of EOF, for example,
// official bttrack shutdowns socket after sending first 48 bytes of
// handshake in its NAT checking.
// So if there are data in resbuf, return it without checking socket
// status.
} else {
size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
if(remaining > 0 && !socket->isReadable(0)) {
dataLength = 0;
return false;
}
bool retval = true;
if(remaining > 0) {
size_t temp = remaining;
readData(resbuf+resbufLength, remaining, _encryptionEnabled);
@ -150,6 +158,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
retval = false;
}
}
}
size_t writeLength = std::min(resbufLength, dataLength);
memcpy(data, resbuf, writeLength);
dataLength = writeLength;