ext/pipe.cpp in eventmachine-0.12.2 vs ext/pipe.cpp in eventmachine-0.12.4
- old
+ new
@@ -1,8 +1,8 @@
/*****************************************************************************
-$Id: pipe.cpp 668 2008-01-04 23:00:34Z blackhedd $
+$Id$
File: pipe.cpp
Date: 30May07
Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
@@ -90,18 +90,25 @@
* This hack won't make it impossible to run multiple EventMachines in a single
* process, but it will make it impossible to reliably nest unbind calls
* within other unbind calls. (Not sure if that's even possible.)
*/
- struct timespec req = {0, 10000000};
- kill (SubprocessPid, SIGTERM);
- nanosleep (&req, NULL);
assert (MyEventMachine);
+
+ // check if the process is already dead
if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
- kill (SubprocessPid, SIGKILL);
+ kill (SubprocessPid, SIGTERM);
+ // wait 0.25s for process to die
+ struct timespec req = {0, 250000000};
nanosleep (&req, NULL);
- if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0)
- throw std::runtime_error ("unable to reap subprocess");
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0) {
+ kill (SubprocessPid, SIGKILL);
+ // wait 0.5s for process to die
+ struct timespec req = {0, 500000000};
+ nanosleep (&req, NULL);
+ if (waitpid (SubprocessPid, &(MyEventMachine->SubprocessExitStatus), WNOHANG) == 0)
+ throw std::runtime_error ("unable to reap subprocess");
+ }
}
}