void update(IOState iostate, FDMultiplexer::callbackfunc_t callback = FDMultiplexer::callbackfunc_t(), FDMultiplexer::funcparam_t callbackData = boost::any(), boost::optional<struct timeval> ttd = boost::none)
{
DEBUGLOG("in "<<__PRETTY_FUNCTION__<<" for fd "<<d_fd<<", last state was "<<(int)d_currentState<<", new state is "<<(int)iostate);
- if (d_currentState == IOState::NeedRead && iostate != IOState::NeedRead) {
+ if (d_currentState == IOState::NeedRead && iostate == IOState::Done) {
DEBUGLOG(__PRETTY_FUNCTION__<<": remove read FD "<<d_fd);
d_mplexer->removeReadFD(d_fd);
d_currentState = IOState::Done;
}
- else if (d_currentState == IOState::NeedWrite && iostate != IOState::NeedWrite) {
+ else if (d_currentState == IOState::NeedWrite && iostate == IOState::Done) {
DEBUGLOG(__PRETTY_FUNCTION__<<": remove write FD "<<d_fd);
d_mplexer->removeWriteFD(d_fd);
d_currentState = IOState::Done;
return;
}
+ if (d_currentState == IOState::NeedWrite) {
+ d_mplexer->alterFDToRead(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+ DEBUGLOG(__PRETTY_FUNCTION__<<": alter from write to read FD "<<d_fd);
+ }
+ else {
+ d_mplexer->addReadFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+ DEBUGLOG(__PRETTY_FUNCTION__<<": add read FD "<<d_fd);
+ }
+
d_currentState = IOState::NeedRead;
- DEBUGLOG(__PRETTY_FUNCTION__<<": add read FD "<<d_fd);
- d_mplexer->addReadFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+
}
else if (iostate == IOState::NeedWrite) {
if (d_currentState == IOState::NeedWrite) {
return;
}
+ if (d_currentState == IOState::NeedRead) {
+ d_mplexer->alterFDToWrite(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+ DEBUGLOG(__PRETTY_FUNCTION__<<": alter from read to write FD "<<d_fd);
+ }
+ else {
+ d_mplexer->addWriteFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
+ DEBUGLOG(__PRETTY_FUNCTION__<<": add write FD "<<d_fd);
+ }
+
d_currentState = IOState::NeedWrite;
- DEBUGLOG(__PRETTY_FUNCTION__<<": add write FD "<<d_fd);
- d_mplexer->addWriteFD(d_fd, callback, callbackData, ttd ? &*ttd : nullptr);
}
else if (iostate == IOState::Done) {
d_currentState = IOState::Done;