From 29946368c45dce5da116adb426362ee93c507c4e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 5 Oct 2010 00:13:02 +0000 Subject: start using kgio, the kinder, gentler I/O library This should hopefully make the non-blocking accept() situation more tolerable under Ruby 1.9.2. --- lib/unicorn/http_request.rb | 3 +-- lib/unicorn/socket_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'lib/unicorn') diff --git a/lib/unicorn/http_request.rb b/lib/unicorn/http_request.rb index 4355ad7..7519170 100644 --- a/lib/unicorn/http_request.rb +++ b/lib/unicorn/http_request.rb @@ -18,7 +18,6 @@ class Unicorn::HttpRequest } NULL_IO = StringIO.new("") - LOCALHOST = '127.0.0.1' # :stopdoc: # A frozen format for this is about 15% faster @@ -62,7 +61,7 @@ class Unicorn::HttpRequest # identify the client for the immediate request to the server; # that client may be a proxy, gateway, or other intermediary # acting on behalf of the actual source client." - @env[REMOTE_ADDR] = TCPSocket === socket ? socket.peeraddr[-1] : LOCALHOST + @env[REMOTE_ADDR] = socket.kgio_addr # short circuit the common case with small GET requests first if @parser.headers(@env, socket.readpartial(16384, @buf)).nil? diff --git a/lib/unicorn/socket_helper.rb b/lib/unicorn/socket_helper.rb index 1d03eab..7364937 100644 --- a/lib/unicorn/socket_helper.rb +++ b/lib/unicorn/socket_helper.rb @@ -126,12 +126,12 @@ module Unicorn end old_umask = File.umask(opt[:umask] || 0) begin - UNIXServer.new(address) + Kgio::UNIXServer.new(address) ensure File.umask(old_umask) end elsif address =~ /^(\d+\.\d+\.\d+\.\d+):(\d+)$/ - TCPServer.new($1, $2.to_i) + Kgio::TCPServer.new($1, $2.to_i) else raise ArgumentError, "Don't know how to bind: #{address}" end @@ -166,9 +166,9 @@ module Unicorn def server_cast(sock) begin Socket.unpack_sockaddr_in(sock.getsockname) - TCPServer.for_fd(sock.fileno) + Kgio::TCPServer.for_fd(sock.fileno) rescue ArgumentError - UNIXServer.for_fd(sock.fileno) + Kgio::UNIXServer.for_fd(sock.fileno) end end -- cgit v1.2.3-24-ge0c7