use milliseconds
This commit is contained in:
parent
a04f83930f
commit
9c8c17f577
@ -49,12 +49,12 @@ namespace ix
|
||||
return;
|
||||
}
|
||||
|
||||
PollResultType pollResult = isReadyToRead(timeoutSecs, 0);
|
||||
PollResultType pollResult = isReadyToRead(1000 * timeoutSecs);
|
||||
|
||||
if (onPollCallback) onPollCallback(pollResult);
|
||||
}
|
||||
|
||||
PollResultType Socket::select(bool readyToRead, int timeoutSecs, int timeoutMs)
|
||||
PollResultType Socket::select(bool readyToRead, int timeoutMs)
|
||||
{
|
||||
fd_set rfds;
|
||||
fd_set wfds;
|
||||
@ -73,15 +73,18 @@ namespace ix
|
||||
}
|
||||
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = timeoutSecs;
|
||||
timeout.tv_usec = 1000 * timeoutMs;
|
||||
timeout.tv_sec = timeoutMs / 1000;
|
||||
timeout.tv_usec = (timeoutMs < 1000) ? 0 : 1000 * (timeoutMs % 1000);
|
||||
|
||||
//std::cerr << "timeout.tv_sec = " << timeout.tv_sec << std::endl;
|
||||
//std::cerr << "timeout.tv_usec = " << timeout.tv_sec << std::endl;
|
||||
|
||||
// Compute the highest fd.
|
||||
int sockfd = _sockfd;
|
||||
int nfds = (std::max)(sockfd, interruptFd);
|
||||
|
||||
int ret = ::select(nfds + 1, &rfds, &wfds, nullptr,
|
||||
(timeoutSecs < 0) ? nullptr : &timeout);
|
||||
(timeoutMs < 0) ? nullptr : &timeout);
|
||||
|
||||
PollResultType pollResult = PollResultType_ReadyForRead;
|
||||
if (ret < 0)
|
||||
@ -121,16 +124,16 @@ namespace ix
|
||||
return pollResult;
|
||||
}
|
||||
|
||||
PollResultType Socket::isReadyToRead(int timeoutSecs, int timeoutMs)
|
||||
PollResultType Socket::isReadyToRead(int timeoutMs)
|
||||
{
|
||||
bool readyToRead = true;
|
||||
return select(readyToRead, timeoutSecs, timeoutMs);
|
||||
return select(readyToRead, timeoutMs);
|
||||
}
|
||||
|
||||
PollResultType Socket::isReadyToWrite(int timeoutSecs, int timeoutMs)
|
||||
PollResultType Socket::isReadyToWrite(int timeoutMs)
|
||||
{
|
||||
bool readyToRead = false;
|
||||
return select(readyToRead, timeoutSecs, timeoutMs);
|
||||
return select(readyToRead, timeoutMs);
|
||||
}
|
||||
|
||||
// Wake up from poll/select by writing to the pipe which is watched by select
|
||||
@ -262,7 +265,7 @@ namespace ix
|
||||
{
|
||||
// Wait with a 1ms timeout until the socket is ready to read.
|
||||
// This way we are not busy looping
|
||||
if (isReadyToRead(0, 1) == PollResultType_Error)
|
||||
if (isReadyToRead(1) == PollResultType_Error)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -331,7 +334,7 @@ namespace ix
|
||||
|
||||
// Wait with a 1ms timeout until the socket is ready to read.
|
||||
// This way we are not busy looping
|
||||
if (isReadyToRead(0, 1) == PollResultType_Error)
|
||||
if (isReadyToRead(1) == PollResultType_Error)
|
||||
{
|
||||
return std::make_pair(false, std::string());
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ namespace ix
|
||||
int timeoutSecs = kDefaultPollTimeout);
|
||||
bool wakeUpFromPoll(uint8_t wakeUpCode);
|
||||
|
||||
PollResultType select(bool readyToRead, int timeoutSecs, int timeoutMs);
|
||||
PollResultType isReadyToWrite(int timeoutSecs, int timeoutMs);
|
||||
PollResultType isReadyToRead(int timeoutSecs, int timeoutMs);
|
||||
PollResultType select(bool readyToRead, int timeoutMs);
|
||||
PollResultType isReadyToWrite(int timeoutMs);
|
||||
PollResultType isReadyToRead(int timeoutMs);
|
||||
|
||||
// Virtual methods
|
||||
virtual bool connect(const std::string& url,
|
||||
|
@ -204,7 +204,7 @@ namespace ix
|
||||
{
|
||||
// Wait with a 10ms timeout until the socket is ready to write.
|
||||
// This way we are not busy looping
|
||||
PollResultType result = _socket->isReadyToWrite(0, 10);
|
||||
PollResultType result = _socket->isReadyToWrite(10);
|
||||
if (result == PollResultType_Error)
|
||||
{
|
||||
_socket->close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user