Changeset 1027

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.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/scripts/checks.m4

    r1013 r1027  
    370370 
    371371    else 
    372       if eval xmlrpc-c-config --version 2>/dev/null >/dev/null; then 
    373         CXXFLAGS="$CXXFLAGS `xmlrpc-c-config --cflags server-util`" 
    374         LIBS="$LIBS `xmlrpc-c-config server-util --libs`" 
     372      if test "$withval" = "yes"; then 
     373        xmlrpc_cc_prg="xmlrpc-c-config" 
     374      else 
     375        xmlrpc_cc_prg="$withval" 
     376      fi 
     377       
     378      if eval $xmlrpc_cc_prg --version 2>/dev/null >/dev/null; then 
     379        CXXFLAGS="$CXXFLAGS `$xmlrpc_cc_prg --cflags server-util`" 
     380        LIBS="$LIBS `$xmlrpc_cc_prg server-util --libs`" 
    375381 
    376382        AC_TRY_LINK( 
  • 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 
  • trunk/rtorrent/scripts/checks.m4

    r987 r1027  
    292292]) 
    293293 
     294AC_DEFUN([TORRENT_CHECK_TR1], [ 
     295  AC_LANG_PUSH(C++) 
     296  AC_MSG_CHECKING(for TR1 support) 
     297 
     298  AC_COMPILE_IFELSE( 
     299    [[#include <tr1/unordered_map> 
     300      class Foo; 
     301      typedef std::tr1::unordered_map<Foo*, int> Bar; 
     302    ]], 
     303    [ 
     304      AC_MSG_RESULT(yes) 
     305      AC_DEFINE(HAVE_TR1, 1, Define to 1 if your C++ library supports the extensions from Technical Report 1) 
     306    ], 
     307    [ 
     308      AC_MSG_RESULT(no) 
     309    ] 
     310  ) 
     311 
     312  AC_LANG_POP(C++) 
     313]) 
    294314 
    295315AC_DEFUN([TORRENT_WITH_FASTCGI], [ 
     
    350370 
    351371    else 
    352       if eval xmlrpc-c-config --version 2>/dev/null >/dev/null; then 
    353         CXXFLAGS="$CXXFLAGS `xmlrpc-c-config --cflags server-util`" 
    354         LIBS="$LIBS `xmlrpc-c-config server-util --libs`" 
     372      if test "$withval" = "yes"; then 
     373        xmlrpc_cc_prg="xmlrpc-c-config" 
     374      else 
     375        xmlrpc_cc_prg="$withval" 
     376      fi 
     377       
     378      if eval $xmlrpc_cc_prg --version 2>/dev/null >/dev/null; then 
     379        CXXFLAGS="$CXXFLAGS `$xmlrpc_cc_prg --cflags server-util`" 
     380        LIBS="$LIBS `$xmlrpc_cc_prg server-util --libs`" 
    355381 
    356382        AC_TRY_LINK(