Show
Ignore:
Timestamp:
01/12/08 13:39:19 (4 years ago)
Author:
rakshasa
Message:

* Fixed a race condition in the handshake read/write code. Patch by
Josef Drexler.

* Fixed the --with-xmlrpc-c autoconf check so that you can pass an
alternative path to an xmlrpc-c-config script.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/src/protocol/handshake.cc

    r1013 r1027  
    526526 
    527527  // The download is just starting so we're not sending any 
    528   // bitfield. 
     528  // bitfield. Pretend we wrote it already. 
    529529  if (m_download->file_list()->bitfield()->is_all_unset()) 
    530     prepare_post_handshake(true); 
     530    m_writePos = m_download->file_list()->bitfield()->size_bytes(); 
    531531  else 
    532532    prepare_bitfield(); 
     
    618618  } 
    619619 
     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 
    620626  if (m_writeDone) 
    621627    throw handshake_succeeded(); 
     
    10211027void 
    10221028Handshake::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 
    10231032  m_state = POST_HANDSHAKE; 
    10241033 
     
    10421051  if (!m_writeBuffer.remaining()) 
    10431052    write_done(); 
    1044  
    1045   // Skip writting the bitfield. 
    1046   m_writePos = m_download->file_list()->bitfield()->size_bytes(); 
    10471053} 
    10481054 
     
    11221128  } 
    11231129 
    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  } 
    11261140} 
    11271141