Merge pull request #13 from machinezone/user/bsergeant/poll
User/bsergeant/poll
This commit is contained in:
commit
7eaea28970
@ -5,5 +5,5 @@ compiler:
|
|||||||
- clang
|
- clang
|
||||||
# - gcc
|
# - gcc
|
||||||
|
|
||||||
os: osx
|
# os: osx
|
||||||
script: make test
|
script: make test
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -37,22 +38,27 @@ namespace ix
|
|||||||
|
|
||||||
void Socket::poll(const OnPollCallback& onPollCallback, int timeoutSecs)
|
void Socket::poll(const OnPollCallback& onPollCallback, int timeoutSecs)
|
||||||
{
|
{
|
||||||
fd_set rfds;
|
if (_sockfd == -1)
|
||||||
FD_ZERO(&rfds);
|
{
|
||||||
FD_SET(_sockfd, &rfds);
|
onPollCallback(PollResultType_Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
FD_SET(_eventfd.getFd(), &rfds);
|
constexpr int nfds = 2;
|
||||||
|
#else
|
||||||
|
constexpr int nfds = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct timeval timeout;
|
struct pollfd fds[nfds];
|
||||||
timeout.tv_sec = timeoutSecs;
|
fds[0].fd = _sockfd;
|
||||||
timeout.tv_usec = 0;
|
fds[0].events = POLLIN;
|
||||||
|
|
||||||
int sockfd = _sockfd;
|
#ifdef __linux__
|
||||||
int nfds = (std::max)(sockfd, _eventfd.getFd());
|
fds[1].fd = _eventfd.getFd();
|
||||||
int ret = select(nfds + 1, &rfds, nullptr, nullptr,
|
fds[1].events = POLLIN;
|
||||||
(timeoutSecs == kDefaultPollNoTimeout) ? nullptr : &timeout);
|
#endif
|
||||||
|
int ret = ::poll(fds, nfds, timeoutSecs * 1000);
|
||||||
|
|
||||||
PollResultType pollResult = PollResultType_ReadyForRead;
|
PollResultType pollResult = PollResultType_ReadyForRead;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -65,6 +71,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
|
|
||||||
onPollCallback(pollResult);
|
onPollCallback(pollResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::wakeUpFromPoll()
|
void Socket::wakeUpFromPoll()
|
||||||
|
@ -30,7 +30,7 @@ sanitizersFlags = {
|
|||||||
}
|
}
|
||||||
sanitizer = 'tsan'
|
sanitizer = 'tsan'
|
||||||
if osName == 'Linux':
|
if osName == 'Linux':
|
||||||
sanitizer = 'asan'
|
sanitizer = 'none'
|
||||||
|
|
||||||
sanitizerFlags = sanitizersFlags[sanitizer]
|
sanitizerFlags = sanitizersFlags[sanitizer]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user