Skip to content

Commit

Permalink
pull pause/resume logic down into EventableDescriptor
Browse files Browse the repository at this point in the history
Fixes pause/resume support on PipeDescriptor and possibly other
connection types. See #245 for more info.
  • Loading branch information
tmm1 authored and rtomayko committed Sep 1, 2011
1 parent eae9baa commit fcaa1a3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions ext/cmain.cpp
Expand Up @@ -220,7 +220,7 @@ evma_pause

extern "C" int evma_pause (const unsigned long binding)
{
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (cd)
return cd->Pause() ? 1 : 0;

Expand All @@ -233,7 +233,7 @@ evma_resume

extern "C" int evma_resume (const unsigned long binding)
{
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (cd)
return cd->Resume() ? 1 : 0;

Expand All @@ -246,7 +246,7 @@ evma_is_paused

extern "C" int evma_is_paused (const unsigned long binding)
{
ConnectionDescriptor *cd = dynamic_cast <ConnectionDescriptor*> (Bindable_t::GetObject (binding));
EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (cd)
return cd->IsPaused() ? 1 : 0;

Expand Down
4 changes: 2 additions & 2 deletions ext/ed.cpp
Expand Up @@ -63,7 +63,8 @@ EventableDescriptor::EventableDescriptor (int sd, EventMachine_t *em):
MaxOutboundBufSize(0),
MyEventMachine (em),
PendingConnectTimeout(20000000),
InactivityTimeout (0)
InactivityTimeout (0),
bPaused (false)
{
/* There are three ways to close a socket, all of which should
* automatically signal to the event machine that this object
Expand Down Expand Up @@ -363,7 +364,6 @@ ConnectionDescriptor::ConnectionDescriptor

ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
EventableDescriptor (sd, em),
bPaused (false),
bConnectPending (false),
bNotifyReadable (false),
bNotifyWritable (false),
Expand Down
9 changes: 4 additions & 5 deletions ext/ed.h
Expand Up @@ -88,9 +88,9 @@ class EventableDescriptor: public Bindable_t
virtual void StopProxy();
virtual void SetProxiedFrom(EventableDescriptor*, const unsigned long);
virtual int SendOutboundData(const char*,int){ return -1; }
virtual bool IsPaused(){ return false; }
virtual bool Pause(){ return false; }
virtual bool Resume(){ return false; }
virtual bool IsPaused(){ return bPaused; }
virtual bool Pause(){ bPaused = true; return bPaused; }
virtual bool Resume(){ bPaused = false; return bPaused; }

void SetUnbindReasonCode(int code){ UnbindReasonCode = code; }
virtual int ReportErrorStatus(){ return 0; }
Expand Down Expand Up @@ -127,6 +127,7 @@ class EventableDescriptor: public Bindable_t
uint64_t InactivityTimeout;
uint64_t LastActivity;
uint64_t NextHeartbeat;
bool bPaused;
};


Expand Down Expand Up @@ -170,7 +171,6 @@ class ConnectionDescriptor: public EventableDescriptor
void SetNotifyWritable (bool);
void SetWatchOnly (bool);

bool IsPaused(){ return bPaused; }
bool Pause();
bool Resume();

Expand Down Expand Up @@ -217,7 +217,6 @@ class ConnectionDescriptor: public EventableDescriptor
};

protected:
bool bPaused;
bool bConnectPending;

bool bNotifyReadable;
Expand Down
4 changes: 2 additions & 2 deletions ext/pipe.cpp
Expand Up @@ -282,7 +282,7 @@ bool PipeDescriptor::SelectForRead()
* a pending state, so this is simpler than for the
* ConnectionDescriptor object.
*/
return true;
return bPaused ? false : true;
}

/******************************
Expand All @@ -295,7 +295,7 @@ bool PipeDescriptor::SelectForWrite()
* a pending state, so this is simpler than for the
* ConnectionDescriptor object.
*/
return (GetOutboundDataSize() > 0);
return (GetOutboundDataSize() > 0) && !bPaused ? true : false;
}


Expand Down

0 comments on commit fcaa1a3

Please sign in to comment.