fix bug with isReadyToWrite
This commit is contained in:
parent
fead661ab7
commit
ceba8ae620
@ -122,6 +122,7 @@ namespace ix
|
|||||||
|
|
||||||
uint64_t value = 0;
|
uint64_t value = 0;
|
||||||
::read(fd, &value, sizeof(value));
|
::read(fd, &value, sizeof(value));
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,6 @@ namespace ix
|
|||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
|
|
||||||
fd_set* fds = (readyToRead) ? &rfds : & wfds;
|
fd_set* fds = (readyToRead) ? &rfds : & wfds;
|
||||||
|
|
||||||
FD_SET(_sockfd, fds);
|
FD_SET(_sockfd, fds);
|
||||||
|
|
||||||
// File descriptor used to interrupt select when needed
|
// File descriptor used to interrupt select when needed
|
||||||
@ -76,9 +75,6 @@ namespace ix
|
|||||||
timeout.tv_sec = timeoutMs / 1000;
|
timeout.tv_sec = timeoutMs / 1000;
|
||||||
timeout.tv_usec = (timeoutMs < 1000) ? 0 : 1000 * (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.
|
// Compute the highest fd.
|
||||||
int sockfd = _sockfd;
|
int sockfd = _sockfd;
|
||||||
int nfds = (std::max)(sockfd, interruptFd);
|
int nfds = (std::max)(sockfd, interruptFd);
|
||||||
@ -95,7 +91,7 @@ namespace ix
|
|||||||
{
|
{
|
||||||
pollResult = PollResultType_Timeout;
|
pollResult = PollResultType_Timeout;
|
||||||
}
|
}
|
||||||
else if (interruptFd != -1 && FD_ISSET(interruptFd, fds))
|
else if (interruptFd != -1 && FD_ISSET(interruptFd, &rfds))
|
||||||
{
|
{
|
||||||
uint64_t value = _selectInterrupt->read();
|
uint64_t value = _selectInterrupt->read();
|
||||||
|
|
||||||
@ -108,18 +104,14 @@ namespace ix
|
|||||||
pollResult = PollResultType_CloseRequest;
|
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;
|
||||||
{
|
}
|
||||||
pollResult = PollResultType_ReadyForRead;
|
else if (sockfd != -1 && !readyToRead && FD_ISSET(sockfd, &wfds))
|
||||||
}
|
{
|
||||||
else
|
pollResult = PollResultType_ReadyForWrite;
|
||||||
{
|
|
||||||
pollResult = PollResultType_ReadyForWrite;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return pollResult;
|
return pollResult;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ namespace ix
|
|||||||
int timeoutSecs = kDefaultPollTimeout);
|
int timeoutSecs = kDefaultPollTimeout);
|
||||||
bool wakeUpFromPoll(uint8_t wakeUpCode);
|
bool wakeUpFromPoll(uint8_t wakeUpCode);
|
||||||
|
|
||||||
PollResultType select(bool readyToRead, int timeoutMs);
|
|
||||||
PollResultType isReadyToWrite(int timeoutMs);
|
PollResultType isReadyToWrite(int timeoutMs);
|
||||||
PollResultType isReadyToRead(int timeoutMs);
|
PollResultType isReadyToRead(int timeoutMs);
|
||||||
|
|
||||||
@ -92,6 +91,8 @@ namespace ix
|
|||||||
std::mutex _socketMutex;
|
std::mutex _socketMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PollResultType select(bool readyToRead, int timeoutMs);
|
||||||
|
|
||||||
static const int kDefaultPollTimeout;
|
static const int kDefaultPollTimeout;
|
||||||
static const int kDefaultPollNoTimeout;
|
static const int kDefaultPollNoTimeout;
|
||||||
|
|
||||||
|
@ -205,14 +205,14 @@ namespace ix
|
|||||||
// Wait with a 10ms timeout until the socket is ready to write.
|
// Wait with a 10ms timeout until the socket is ready to write.
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
// FIXME: why are we not getting PollResultType_ReadyForWrite ??
|
else if (result == PollResultType_ReadyForWrite)
|
||||||
else // if (result == PollResultType_ReadyForWrite)
|
|
||||||
{
|
{
|
||||||
sendOnSocket();
|
sendOnSocket();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
#!/bin/sh
|
#!/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
|
rm -rf /tmp/ws_test
|
||||||
mkdir -p /tmp/ws_test
|
mkdir -p /tmp/ws_test
|
||||||
|
|
||||||
@ -21,11 +31,11 @@ done
|
|||||||
# Start a receiver
|
# Start a receiver
|
||||||
mkdir -p /tmp/ws_test/receive
|
mkdir -p /tmp/ws_test/receive
|
||||||
cd /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
|
mkdir /tmp/ws_test/send
|
||||||
cd /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
|
# Start the sender job
|
||||||
ws send --pidfile /tmp/ws_test/pidfile.send ws://127.0.0.1:8090 20M_file
|
ws send --pidfile /tmp/ws_test/pidfile.send ws://127.0.0.1:8090 20M_file
|
||||||
|
Loading…
Reference in New Issue
Block a user