mirror of
https://github.com/aria2/aria2.git
synced 2025-02-19 05:37:49 +00:00
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:
parent
5cbab84b65
commit
249194ba8d
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user