| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "Select.hpp" |
| 2 |
|
|
#include "../utils/GuiException.hpp" |
| 3 |
|
|
|
| 4 |
|
|
#include <algorithm> |
| 5 |
|
|
|
| 6 |
|
77 |
Select::Select() : max_fd(-1) { |
| 7 |
2/2
✓ Branch 0 taken 1232 times.
✓ Branch 1 taken 77 times.
|
1309 |
FD_ZERO(&read_fds); |
| 8 |
|
77 |
} |
| 9 |
|
|
|
| 10 |
|
74 |
Select::~Select() { |
| 11 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 74 times.
|
79 |
while (max_fd >= 0) { |
| 12 |
|
5 |
removeFd(max_fd); |
| 13 |
|
|
} |
| 14 |
|
74 |
} |
| 15 |
|
|
|
| 16 |
|
6 |
void Select::addFd(int fd) { |
| 17 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 |
FD_SET(fd, &read_fds); |
| 18 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
max_fd = std::max(max_fd, fd); |
| 19 |
|
6 |
} |
| 20 |
|
|
|
| 21 |
|
6 |
void Select::removeFd(int fd) { |
| 22 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
6 |
FD_CLR(fd, &read_fds); |
| 23 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
if (fd == max_fd) { |
| 24 |
4/8
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 8 taken 36 times.
✗ Branch 9 not taken.
|
42 |
while (max_fd >= 0 && !FD_ISSET(max_fd, &read_fds)) { |
| 25 |
|
36 |
--max_fd; |
| 26 |
|
|
} |
| 27 |
|
|
} |
| 28 |
|
6 |
} |
| 29 |
|
|
|
| 30 |
|
2 |
bool Select::isSet(int fd) const { |
| 31 |
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 |
return FD_ISSET(fd, &read_fds); |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
2 |
int Select::select() { |
| 35 |
|
2 |
fd_set copy_fds = read_fds; |
| 36 |
|
|
struct timeval tv; |
| 37 |
|
2 |
tv.tv_sec = 0; |
| 38 |
|
2 |
tv.tv_usec = 0; |
| 39 |
|
2 |
int ret = ::select(max_fd + 1, ©_fds, nullptr, nullptr, &tv); |
| 40 |
|
|
|
| 41 |
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 |
if (ret == -1) |
| 42 |
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 |
throw guiException("Select::select: select failed"); |
| 43 |
|
1 |
return ret; |
| 44 |
|
|
} |
| 45 |
|
|
|