Changeset 1027 for trunk/libtorrent/src/protocol/handshake.cc
- Timestamp:
- 01/12/08 13:39:19 (4 years ago)
- Files:
-
- 1 modified
-
trunk/libtorrent/src/protocol/handshake.cc (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtorrent/src/protocol/handshake.cc
r1013 r1027 526 526 527 527 // The download is just starting so we're not sending any 528 // bitfield. 528 // bitfield. Pretend we wrote it already. 529 529 if (m_download->file_list()->bitfield()->is_all_unset()) 530 prepare_post_handshake(true);530 m_writePos = m_download->file_list()->bitfield()->size_bytes(); 531 531 else 532 532 prepare_bitfield(); … … 618 618 } 619 619 620 // Should've started to write post handshake data already, but we were 621 // still reading the bitfield/extension and postponed it. If we had no 622 // bitfield to send, we need to send a keep-alive now. 623 if (m_writePos == m_download->file_list()->bitfield()->size_bytes()) 624 prepare_post_handshake(m_download->file_list()->bitfield()->is_all_unset()); 625 620 626 if (m_writeDone) 621 627 throw handshake_succeeded(); … … 1021 1027 void 1022 1028 Handshake::prepare_post_handshake(bool must_write) { 1029 if (m_writePos != m_download->file_list()->bitfield()->size_bytes()) 1030 throw internal_error("Handshake::prepare_post_handshake called while bitfield not written completely."); 1031 1023 1032 m_state = POST_HANDSHAKE; 1024 1033 … … 1042 1051 if (!m_writeBuffer.remaining()) 1043 1052 write_done(); 1044 1045 // Skip writting the bitfield.1046 m_writePos = m_download->file_list()->bitfield()->size_bytes();1047 1053 } 1048 1054 … … 1122 1128 } 1123 1129 1124 if (m_writePos == bitfield->size_bytes()) 1125 prepare_post_handshake(false); 1130 // We can't call prepare_post_handshake until the read code is done reading 1131 // the bitfield, so if we get here before then, postpone the post handshake 1132 // data until reading is done. Since we're done writing, remove us from the 1133 // poll in that case. 1134 if (m_writePos == bitfield->size_bytes()) { 1135 if (!m_readDone) 1136 manager->poll()->remove_write(this); 1137 else 1138 prepare_post_handshake(false); 1139 } 1126 1140 } 1127 1141
