Skip to content

Instantly share code, notes, and snippets.

@raphael
Created March 1, 2009 08:42
Show Gist options
  • Save raphael/72279 to your computer and use it in GitHub Desktop.
Save raphael/72279 to your computer and use it in GitHub Desktop.
diff --git a/ext/ed.cpp b/ext/ed.cpp
index 9253550..1188ad4 100644
--- a/ext/ed.cpp
+++ b/ext/ed.cpp
@@ -175,6 +175,7 @@ ConnectionDescriptor::ConnectionDescriptor
ConnectionDescriptor::ConnectionDescriptor (int sd, EventMachine_t *em):
EventableDescriptor (sd, em),
bConnectPending (false),
+ bRecentlyAttached (false),
bNotifyReadable (false),
bNotifyWritable (false),
bReadAttemptedAfterClose (false),
@@ -276,6 +277,15 @@ void ConnectionDescriptor::SetConnectPending(bool f)
}
+/***************************************
+ConnectionDescriptor::SetRecentlyAttached
+****************************************/
+
+void ConnectionDescriptor::SetRecentlyAttached(bool f)
+{
+ bRecentlyAttached = f;
+}
+
/**************************************
ConnectionDescriptor::SendOutboundData
**************************************/
@@ -379,9 +389,11 @@ bool ConnectionDescriptor::SelectForWrite()
* In a pending-connect state, we ALWAYS select for writable.
* In a normal state, we only select for writable when we
* have outgoing data to send.
+ * If there was no select nor write since the connection was
+ * attached then we ALWAYS select for writable.
*/
- if (bConnectPending || bNotifyWritable)
+ if (bConnectPending || bNotifyWritable || bRecentlyAttached)
return true;
else {
return (GetOutboundDataSize() > 0);
@@ -555,7 +567,7 @@ void ConnectionDescriptor::Write()
* errors will have to be caught by the timeout mechanism.
*/
- if (bConnectPending) {
+ if (bConnectPending || bRecentlyAttached) {
int error;
socklen_t len;
len = sizeof(error);
@@ -569,6 +581,7 @@ void ConnectionDescriptor::Write()
if (EventCallback)
(*EventCallback)(GetBinding().c_str(), EM_CONNECTION_COMPLETED, "", 0);
bConnectPending = false;
+ bRecentlyAttached = false;
#ifdef HAVE_EPOLL
// The callback may have scheduled outbound data.
EpollEvent.events = EPOLLIN | (SelectForWrite() ? EPOLLOUT : 0);
diff --git a/ext/ed.h b/ext/ed.h
index cca7844..4b6c728 100644
--- a/ext/ed.h
+++ b/ext/ed.h
@@ -152,6 +152,7 @@ class ConnectionDescriptor: public EventableDescriptor
int SendOutboundData (const char*, int);
void SetConnectPending (bool f);
+ void SetRecentlyAttached (bool f);
void SetNotifyReadable (bool readable) { bNotifyReadable = readable; }
void SetNotifyWritable (bool writable) { bNotifyWritable = writable; }
@@ -193,6 +194,7 @@ class ConnectionDescriptor: public EventableDescriptor
protected:
bool bConnectPending;
+ bool bRecentlyAttached;
bool bNotifyReadable;
bool bNotifyWritable;
diff --git a/ext/em.cpp b/ext/em.cpp
index e2c9bd5..98d50f5 100644
--- a/ext/em.cpp
+++ b/ext/em.cpp
@@ -1236,7 +1236,7 @@ const char *EventMachine_t::AttachFD (int fd, bool notify_readable, bool notify_
if (!cd)
throw std::runtime_error ("no connection allocated");
- cd->SetConnectPending (true);
+ cd->SetRecentlyAttached (true);
cd->SetNotifyReadable (notify_readable);
cd->SetNotifyWritable (notify_writable);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment