Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #242 from vishnugopal/never-close-stdin-out-err

Never close STDIN, STDOUT and STDERR (i.e. only close when fd > 2) Should
  • Loading branch information...
commit 5222bcd4fc3eccbf19212cd007c6f9bb42122538 2 parents 1175645 + 3bcbb5c
@tmm1 tmm1 authored
Showing with 15 additions and 7 deletions.
  1. +12 −4 ext/ed.cpp
  2. +2 −2 ext/em.cpp
  3. +1 −1  ext/em.h
View
16 ext/ed.cpp
@@ -168,13 +168,21 @@ void EventableDescriptor::Close()
* Therefore, it is necessary to notify EventMachine that
* the fd associated with this EventableDescriptor is
* closing.
+ *
+ * EventMachine also never closes fds for STDIN, STDOUT and
+ * STDERR (0, 1 & 2)
*/
// Close the socket right now. Intended for emergencies.
- if (MySocket != INVALID_SOCKET && !bWatchOnly) {
- MyEventMachine->Closing (this);
- shutdown (MySocket, 1);
- close (MySocket);
+ if (MySocket != INVALID_SOCKET) {
+ MyEventMachine->Deregister (this);
+
+ // Do not close STDIN, STDOUT, STDERR
+ if (MySocket > 2 && !bWatchOnly) {
+ shutdown (MySocket, 1);
+ close (MySocket);
+ }
+
MySocket = INVALID_SOCKET;
}
}
View
4 ext/em.cpp
@@ -1789,10 +1789,10 @@ void EventMachine_t::Modify (EventableDescriptor *ed)
/***********************
-EventMachine_t::Closing
+EventMachine_t::Deregister
***********************/
-void EventMachine_t::Closing (EventableDescriptor *ed)
+void EventMachine_t::Deregister (EventableDescriptor *ed)
{
if (!ed)
throw std::runtime_error ("modified bad descriptor");
View
2  ext/em.h
@@ -90,7 +90,7 @@ class EventMachine_t
void Add (EventableDescriptor*);
void Modify (EventableDescriptor*);
- void Closing (EventableDescriptor*);
+ void Deregister (EventableDescriptor*);
const unsigned long AttachFD (int, bool);
int DetachFD (EventableDescriptor*);
Please sign in to comment.
Something went wrong with that request. Please try again.