summaryrefslogtreecommitdiffstats
path: root/script/git-daemon
diff options
context:
space:
mode:
authorJohan Sørensen <johan@johansorensen.com>2009-03-02 12:42:33 +0100
committerJohan Sørensen <johan@johansorensen.com>2009-04-22 15:15:17 +0200
commitd341dce535e32aa756b720b222ad8a4deb7c0a38 (patch)
tree1e35bae59af64978c1cc915103ecc0338fce90ba /script/git-daemon
parentd5f245660e9784e4bf7bf9acf5fdd09c4ad83477 (diff)
downloadgitorious-mainline-outdated-d341dce535e32aa756b720b222ad8a4deb7c0a38.zip
gitorious-mainline-outdated-d341dce535e32aa756b720b222ad8a4deb7c0a38.tar.gz
gitorious-mainline-outdated-d341dce535e32aa756b720b222ad8a4deb7c0a38.tar.bz2
Use non-blocking sockets on 1.9 in the git-daemon
Diffstat (limited to 'script/git-daemon')
-rwxr-xr-xscript/git-daemon36
1 files changed, 34 insertions, 2 deletions
diff --git a/script/git-daemon b/script/git-daemon
index aba1ba6..f736770 100755
--- a/script/git-daemon
+++ b/script/git-daemon
@@ -47,7 +47,7 @@ module Git
end
def run
- while session = @socket.accept
+ while session = accept_socket
connections = $children_active - $children_reaped
if connections > MAX_CHILDREN
log(Process.pid, "too many active children #{connections}/#{MAX_CHILDREN}")
@@ -63,7 +63,7 @@ module Git
$children_active += 1
ip_family, port, name, ip = session.peeraddr
- line = session.recv(1000)
+ line = receive_data(session)
if line =~ SERVICE_REGEXP
start_time = Time.now
@@ -167,6 +167,38 @@ module Git
def log(pid, msg)
$stderr.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")} [#{pid}] #{msg}"
end
+
+ def accept_socket
+ if RUBY_VERSION < '1.9'
+ @socket.accept
+ else
+ begin
+ @socket.accept_nonblock
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR => e
+ if IO.select([@socket])
+ retry
+ else
+ raise e
+ end
+ end
+ end
+ end
+
+ def receive_data(session)
+ if RUBY_VERSION < '1.9'
+ session.recv(1000)
+ else
+ begin
+ session.recv_nonblock(1000)
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
+ if IO.select([@socket])
+ retry
+ else
+ return ""
+ end
+ end
+ end
+ end
end
end