summaryrefslogtreecommitdiff
path: root/src/PeerConnection.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2007-10-11 16:58:24 +0000
commit048a2cf59737f761876e81a77e8d064c45c752d7 (patch)
tree65c9d5498aafe6a8c8e640ddfcc43c7013504d0d /src/PeerConnection.cc
parente26bbbb9eee140ba24402fe872a752b42f0077de (diff)
2007-10-12 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Implemented BitTorrent/http/ftp integrated download. I've rewritten lots of files and now some headers have forward class declarations to reduce compile time. The implementation is extremely alpha stage, I recommend to use this for testing purpose only.
Diffstat (limited to 'src/PeerConnection.cc')
-rw-r--r--src/PeerConnection.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/PeerConnection.cc b/src/PeerConnection.cc
index fd231997..e62e1e25 100644
--- a/src/PeerConnection.cc
+++ b/src/PeerConnection.cc
@@ -122,17 +122,20 @@ bool PeerConnection::receiveMessage(unsigned char* data, int32_t& dataLength) {
return true;
}
-bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength) {
- if(!socket->isReadable(0)) {
+bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength,
+ bool peek) {
+ int32_t remain = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
+ if(remain != 0 && !socket->isReadable(0)) {
dataLength = 0;
return false;
}
- int32_t remain = BtHandshakeMessage::MESSAGE_LENGTH-resbufLength;
int32_t temp = remain;
- socket->readData((char*)resbuf+resbufLength, temp);
- if(temp == 0) {
- // we got EOF
- throw new DlAbortEx(EX_EOF_FROM_PEER);
+ if(remain != 0) {
+ socket->readData((char*)resbuf+resbufLength, temp);
+ if(temp == 0) {
+ // we got EOF
+ throw new DlAbortEx(EX_EOF_FROM_PEER);
+ }
}
bool retval;
if(remain != temp) {
@@ -141,11 +144,11 @@ bool PeerConnection::receiveHandshake(unsigned char* data, int32_t& dataLength)
retval = true;
}
resbufLength += temp;
- // we got whole handshake payload
+
int32_t writeLength = resbufLength > dataLength ? dataLength : resbufLength;
memcpy(data, resbuf, writeLength);
dataLength = writeLength;
- if(retval) {
+ if(retval && !peek) {
resbufLength = 0;
}
return retval;