make PollResultType an enum class
This commit is contained in:
parent
13f4aee5ee
commit
523a6e989a
@ -45,7 +45,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
if (_sockfd == -1)
|
if (_sockfd == -1)
|
||||||
{
|
{
|
||||||
if (onPollCallback) onPollCallback(PollResultType_Error);
|
if (onPollCallback) onPollCallback(PollResultType::Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,14 +82,14 @@ namespace ix
|
|||||||
int ret = ::select(nfds + 1, &rfds, &wfds, nullptr,
|
int ret = ::select(nfds + 1, &rfds, &wfds, nullptr,
|
||||||
(timeoutMs < 0) ? nullptr : &timeout);
|
(timeoutMs < 0) ? nullptr : &timeout);
|
||||||
|
|
||||||
PollResultType pollResult = PollResultType_ReadyForRead;
|
PollResultType pollResult = PollResultType::ReadyForRead;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_Error;
|
pollResult = PollResultType::Error;
|
||||||
}
|
}
|
||||||
else if (ret == 0)
|
else if (ret == 0)
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_Timeout;
|
pollResult = PollResultType::Timeout;
|
||||||
}
|
}
|
||||||
else if (interruptFd != -1 && FD_ISSET(interruptFd, &rfds))
|
else if (interruptFd != -1 && FD_ISSET(interruptFd, &rfds))
|
||||||
{
|
{
|
||||||
@ -97,20 +97,20 @@ namespace ix
|
|||||||
|
|
||||||
if (value == kSendRequest)
|
if (value == kSendRequest)
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_SendRequest;
|
pollResult = PollResultType::SendRequest;
|
||||||
}
|
}
|
||||||
else if (value == kCloseRequest)
|
else if (value == kCloseRequest)
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_CloseRequest;
|
pollResult = PollResultType::CloseRequest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sockfd != -1 && readyToRead && FD_ISSET(sockfd, &rfds))
|
else if (sockfd != -1 && readyToRead && FD_ISSET(sockfd, &rfds))
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_ReadyForRead;
|
pollResult = PollResultType::ReadyForRead;
|
||||||
}
|
}
|
||||||
else if (sockfd != -1 && !readyToRead && FD_ISSET(sockfd, &wfds))
|
else if (sockfd != -1 && !readyToRead && FD_ISSET(sockfd, &wfds))
|
||||||
{
|
{
|
||||||
pollResult = PollResultType_ReadyForWrite;
|
pollResult = PollResultType::ReadyForWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pollResult;
|
return pollResult;
|
||||||
@ -257,7 +257,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
// Wait with a 1ms timeout until the socket is ready to read.
|
// Wait with a 1ms timeout until the socket is ready to read.
|
||||||
// This way we are not busy looping
|
// This way we are not busy looping
|
||||||
if (isReadyToRead(1) == PollResultType_Error)
|
if (isReadyToRead(1) == PollResultType::Error)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -326,7 +326,7 @@ namespace ix
|
|||||||
|
|
||||||
// Wait with a 1ms timeout until the socket is ready to read.
|
// Wait with a 1ms timeout until the socket is ready to read.
|
||||||
// This way we are not busy looping
|
// This way we are not busy looping
|
||||||
if (isReadyToRead(1) == PollResultType_Error)
|
if (isReadyToRead(1) == PollResultType::Error)
|
||||||
{
|
{
|
||||||
return std::make_pair(false, std::string());
|
return std::make_pair(false, std::string());
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,14 @@ namespace ix
|
|||||||
{
|
{
|
||||||
class SelectInterrupt;
|
class SelectInterrupt;
|
||||||
|
|
||||||
enum PollResultType
|
enum class PollResultType
|
||||||
{
|
{
|
||||||
PollResultType_ReadyForRead = 0,
|
ReadyForRead = 0,
|
||||||
PollResultType_ReadyForWrite = 1,
|
ReadyForWrite = 1,
|
||||||
PollResultType_Timeout = 2,
|
Timeout = 2,
|
||||||
PollResultType_Error = 3,
|
Error = 3,
|
||||||
PollResultType_SendRequest = 4,
|
SendRequest = 4,
|
||||||
PollResultType_CloseRequest = 5
|
CloseRequest = 5
|
||||||
};
|
};
|
||||||
|
|
||||||
class Socket {
|
class Socket {
|
||||||
|
@ -189,7 +189,7 @@ namespace ix
|
|||||||
// If (1) heartbeat is enabled, and (2) no data was received or
|
// If (1) heartbeat is enabled, and (2) no data was received or
|
||||||
// send for a duration exceeding our heart-beat period, send a
|
// send for a duration exceeding our heart-beat period, send a
|
||||||
// ping to the server.
|
// ping to the server.
|
||||||
if (pollResult == PollResultType_Timeout &&
|
if (pollResult == PollResultType::Timeout &&
|
||||||
heartBeatPeriodExceeded())
|
heartBeatPeriodExceeded())
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
@ -198,7 +198,7 @@ namespace ix
|
|||||||
}
|
}
|
||||||
// Make sure we send all the buffered data
|
// Make sure we send all the buffered data
|
||||||
// there can be a lot of it for large messages.
|
// there can be a lot of it for large messages.
|
||||||
else if (pollResult == PollResultType_SendRequest)
|
else if (pollResult == PollResultType::SendRequest)
|
||||||
{
|
{
|
||||||
while (!isSendBufferEmpty() && !_requestInitCancellation)
|
while (!isSendBufferEmpty() && !_requestInitCancellation)
|
||||||
{
|
{
|
||||||
@ -206,19 +206,19 @@ namespace ix
|
|||||||
// This way we are not busy looping
|
// This way we are not busy looping
|
||||||
PollResultType result = _socket->isReadyToWrite(10);
|
PollResultType result = _socket->isReadyToWrite(10);
|
||||||
|
|
||||||
if (result == PollResultType_Error)
|
if (result == PollResultType::Error)
|
||||||
{
|
{
|
||||||
_socket->close();
|
_socket->close();
|
||||||
setReadyState(CLOSED);
|
setReadyState(CLOSED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (result == PollResultType_ReadyForWrite)
|
else if (result == PollResultType::ReadyForWrite)
|
||||||
{
|
{
|
||||||
sendOnSocket();
|
sendOnSocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (pollResult == PollResultType_ReadyForRead)
|
else if (pollResult == PollResultType::ReadyForRead)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -244,11 +244,11 @@ namespace ix
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (pollResult == PollResultType_Error)
|
else if (pollResult == PollResultType::Error)
|
||||||
{
|
{
|
||||||
_socket->close();
|
_socket->close();
|
||||||
}
|
}
|
||||||
else if (pollResult == PollResultType_CloseRequest)
|
else if (pollResult == PollResultType::CloseRequest)
|
||||||
{
|
{
|
||||||
_socket->close();
|
_socket->close();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user