about summary refs log tree commit homepage
diff options
authorEric Wong <normalperson@yhbt.net>2009-04-12 22:59:03 -0700
committerEric Wong <normalperson@yhbt.net>2009-04-12 22:59:03 -0700
commit96c73021c7b41d609fb8335d0ef986ed16bd2dc3 (patch)
parentfc4bd6c542b6556e746baee5aecadfcd1a591beb (diff)
MRI 1.8 always sets O_NONBLOCK on sockets to implement green
threads correctly in the face of slow network I/O.  Since we
already know what the I/O flags for a client socket should be,
we just set it to that instead.

Applications running on Unicorn continue to be green thread-safe
when used fast local traffic.  Of course, Unicorn itself will
never use threads.
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/unicorn.rb b/lib/unicorn.rb
index 4e82ec6..6313f16 100644
--- a/lib/unicorn.rb
+++ b/lib/unicorn.rb
@@ -403,7 +403,8 @@ module Unicorn
     # once a client is accepted, it is processed in its entirety here
     # in 3 easy steps: read request, call app, write app response
     def process_client(client)
-      client.nonblock = false
+      # one syscall less than "client.nonblock = false":
+      client.fcntl(Fcntl::F_SETFL, File::RDWR)
       env = @request.read(client)
       app_response = @app.call(env)
       HttpResponse.write(client, app_response)
diff --git a/lib/unicorn/socket.rb b/lib/unicorn/socket.rb
index f0c41cf..5a3bfd7 100644
--- a/lib/unicorn/socket.rb
+++ b/lib/unicorn/socket.rb
@@ -1,5 +1,4 @@
 require 'socket'
-require 'io/nonblock'
 class UNIXSocket
   UNICORN_PEERADDR = ''.freeze