mirror of https://github.com/aria2/aria2
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)pull/1/head
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>
|
2008-06-06 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Included stdint.h
|
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 PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
|
||||||
bool peek) {
|
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;
|
size_t remaining = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
|
||||||
if(remaining > 0 && !socket->isReadable(0)) {
|
if(remaining > 0 && !socket->isReadable(0)) {
|
||||||
dataLength = 0;
|
dataLength = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool retval = true;
|
|
||||||
if(remaining > 0) {
|
if(remaining > 0) {
|
||||||
size_t temp = remaining;
|
size_t temp = remaining;
|
||||||
readData(resbuf+resbufLength, remaining, _encryptionEnabled);
|
readData(resbuf+resbufLength, remaining, _encryptionEnabled);
|
||||||
|
@ -150,6 +158,7 @@ bool PeerConnection::receiveHandshake(unsigned char* data, size_t& dataLength,
|
||||||
retval = false;
|
retval = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
size_t writeLength = std::min(resbufLength, dataLength);
|
size_t writeLength = std::min(resbufLength, dataLength);
|
||||||
memcpy(data, resbuf, writeLength);
|
memcpy(data, resbuf, writeLength);
|
||||||
dataLength = writeLength;
|
dataLength = writeLength;
|
||||||
|
|
Loading…
Reference in New Issue