File: network.cc

package info (click to toggle)
libtorrent 0.15.7-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,152 kB
  • sloc: cpp: 35,007; sh: 4,488; ansic: 4,397; makefile: 575; xml: 163
file content (27 lines) | stat: -rw-r--r-- 614 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "config.h"

#include "test/helpers/network.h"

#include <sys/select.h>

#include "torrent/event.h"

bool
check_event_is_readable(torrent::Event* event, std::chrono::microseconds timeout) {
  int fd = event->file_descriptor();

  fd_set read_fds;
  FD_ZERO(&read_fds);
  FD_SET(fd, &read_fds);

  struct timeval t = {
    static_cast<time_t>(std::chrono::duration_cast<std::chrono::seconds>(timeout).count()),
    static_cast<suseconds_t>(timeout.count() % 1000000)
  };

  int result = select(fd + 1, &read_fds, nullptr, nullptr, &t);

  CPPUNIT_ASSERT(result != -1);

  return FD_ISSET(fd, &read_fds);
}