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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user