optimized file_pool lookups and string handling
This commit is contained in:
@@ -60,6 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/peer_info.hpp"
|
||||
#include "libtorrent/socket_io.hpp" // print_address
|
||||
#include "libtorrent/time.hpp"
|
||||
|
||||
using boost::bind;
|
||||
|
||||
@@ -130,16 +131,29 @@ bool sleep_and_input(char* c, int sleep)
|
||||
// sets the terminal to single-character mode
|
||||
// and resets when destructed
|
||||
set_keypress s;
|
||||
|
||||
libtorrent::ptime start = libtorrent::time_now_hires();
|
||||
int ret = 0;
|
||||
retry:
|
||||
fd_set set;
|
||||
FD_ZERO(&set);
|
||||
FD_SET(0, &set);
|
||||
timeval tv = {sleep, 0};
|
||||
if (select(1, &set, 0, 0, &tv) > 0)
|
||||
ret = select(1, &set, 0, 0, &tv);
|
||||
if (ret > 0)
|
||||
{
|
||||
*c = getc(stdin);
|
||||
return true;
|
||||
}
|
||||
if (errno == EINTR)
|
||||
{
|
||||
if (total_milliseconds(libtorrent::time_now_hires() - start) < sleep * 1000)
|
||||
goto retry;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret < 0 && errno != 0 && errno != ETIMEDOUT)
|
||||
fprintf(stderr, "select failed: %s\n", strerror(errno));
|
||||
|
||||
libtorrent::sleep(500);
|
||||
return false;
|
||||
}
|
||||
|
@@ -52,7 +52,9 @@ struct peer_conn
|
||||
: s(ios)
|
||||
, read_pos(0)
|
||||
, state(handshaking)
|
||||
, pieces(num_pieces)
|
||||
// don't request anything from the last piece
|
||||
// to keep things simple
|
||||
, pieces(num_pieces - 1)
|
||||
, block(0)
|
||||
, blocks_per_piece(blocks_pp)
|
||||
, info_hash(ih)
|
||||
@@ -248,6 +250,7 @@ int main(int argc, char const* argv[])
|
||||
conns.push_back(new peer_conn(ios, ti.num_pieces(), ti.piece_length() / 16 / 1024
|
||||
, ep, (char const*)&ti.info_hash()[0]));
|
||||
libtorrent::sleep(1);
|
||||
ios.poll_one();
|
||||
}
|
||||
|
||||
ios.run();
|
||||
|
Reference in New Issue
Block a user