Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #246 from rtomayko/popen-pause

Add pause/resume support for PipeDescriptor
  • Loading branch information...
commit 1829c0ff569cb92f8de20b69c3e9b3441035ae65 2 parents 8f91132 + fcaa1a3
@tmm1 tmm1 authored
View
6 ext/cmain.cpp
@@ -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;
@@ -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;
@@ -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;
View
4 ext/ed.cpp
@@ -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
@@ -363,7 +364,6 @@ ConnectionDescriptor::ConnectionDescriptor
ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
EventableDescriptor (sd, em),
- bPaused (false),
bConnectPending (false),
bNotifyReadable (false),
bNotifyWritable (false),
View
9 ext/ed.h
@@ -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; }
@@ -127,6 +127,7 @@ class EventableDescriptor: public Bindable_t
uint64_t InactivityTimeout;
uint64_t LastActivity;
uint64_t NextHeartbeat;
+ bool bPaused;
};
@@ -170,7 +171,6 @@ class ConnectionDescriptor: public EventableDescriptor
void SetNotifyWritable (bool);
void SetWatchOnly (bool);
- bool IsPaused(){ return bPaused; }
bool Pause();
bool Resume();
@@ -217,7 +217,6 @@ class ConnectionDescriptor: public EventableDescriptor
};
protected:
- bool bPaused;
bool bConnectPending;
bool bNotifyReadable;
View
4 ext/pipe.cpp
@@ -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;
}
/******************************
@@ -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;
}
View
18 tests/test_processes.rb
@@ -99,6 +99,24 @@ def test_em_system_spaced_arguments
assert_equal("hello\n", $out)
end
+
+ def test_em_popen_pause_resume
+ c_rx = 0
+
+ test_client = Module.new do
+ define_method :receive_data do |data|
+ c_rx += 1
+ pause
+ EM.add_timer(0.5) { EM.stop }
+ end
+ end
+
+ EM.run{
+ EM.popen('cat /dev/random', test_client)
+ }
+
+ assert_equal 1, c_rx
+ end
else
warn "EM.popen not implemented, skipping tests in #{__FILE__}"
Please sign in to comment.
Something went wrong with that request. Please try again.