fix bug with isReadyToWrite

This commit is contained in:
Benjamin Sergeant 2019-03-18 22:00:08 -07:00
parent fead661ab7
commit ceba8ae620
5 changed files with 24 additions and 20 deletions

View File

@ -122,6 +122,7 @@ namespace ix
uint64_t value = 0;
::read(fd, &value, sizeof(value));
return value;
}

View File

@ -62,7 +62,6 @@ namespace ix
FD_ZERO(&wfds);
fd_set* fds = (readyToRead) ? &rfds : & wfds;
FD_SET(_sockfd, fds);
// File descriptor used to interrupt select when needed
@ -76,9 +75,6 @@ namespace ix
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);
@ -95,7 +91,7 @@ namespace ix
{
pollResult = PollResultType_Timeout;
}
else if (interruptFd != -1 && FD_ISSET(interruptFd, fds))
else if (interruptFd != -1 && FD_ISSET(interruptFd, &rfds))
{
uint64_t value = _selectInterrupt->read();
@ -108,18 +104,14 @@ namespace ix
pollResult = PollResultType_CloseRequest;
}
}
else if (sockfd != -1 && FD_ISSET(sockfd, fds))
else if (sockfd != -1 && readyToRead && FD_ISSET(sockfd, &rfds))
{
if (readyToRead)
{
pollResult = PollResultType_ReadyForRead;
}
else
{
pollResult = PollResultType_ReadyForWrite;
}
pollResult = PollResultType_ReadyForRead;
}
else if (sockfd != -1 && !readyToRead && FD_ISSET(sockfd, &wfds))
{
pollResult = PollResultType_ReadyForWrite;
}
return pollResult;
}

View File

@ -50,7 +50,6 @@ namespace ix
int timeoutSecs = kDefaultPollTimeout);
bool wakeUpFromPoll(uint8_t wakeUpCode);
PollResultType select(bool readyToRead, int timeoutMs);
PollResultType isReadyToWrite(int timeoutMs);
PollResultType isReadyToRead(int timeoutMs);
@ -92,6 +91,8 @@ namespace ix
std::mutex _socketMutex;
private:
PollResultType select(bool readyToRead, int timeoutMs);
static const int kDefaultPollTimeout;
static const int kDefaultPollNoTimeout;

View File

@ -205,14 +205,14 @@ 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(10);
if (result == PollResultType_Error)
{
_socket->close();
setReadyState(CLOSED);
break;
}
// FIXME: why are we not getting PollResultType_ReadyForWrite ??
else // if (result == PollResultType_ReadyForWrite)
else if (result == PollResultType_ReadyForWrite)
{
sendOnSocket();
}

View File

@ -1,5 +1,15 @@
#!/bin/sh
# Handle Ctrl-C by killing all sub-processing AND exiting
trap cleanup INT
function cleanup {
kill `cat /tmp/ws_test/pidfile.transfer`
kill `cat /tmp/ws_test/pidfile.receive`
kill `cat /tmp/ws_test/pidfile.send`
exit 1
}
rm -rf /tmp/ws_test
mkdir -p /tmp/ws_test
@ -21,11 +31,11 @@ done
# Start a receiver
mkdir -p /tmp/ws_test/receive
cd /tmp/ws_test/receive
ws receive --delay 5 ws://127.0.0.1:8090 --pidfile /tmp/ws_test/pidfile.receive &
ws receive --delay 10 ws://127.0.0.1:8090 --pidfile /tmp/ws_test/pidfile.receive &
mkdir /tmp/ws_test/send
cd /tmp/ws_test/send
dd if=/dev/urandom of=20M_file count=10000 bs=1024
dd if=/dev/urandom of=20M_file count=20000 bs=1024
# Start the sender job
ws send --pidfile /tmp/ws_test/pidfile.send ws://127.0.0.1:8090 20M_file