Skip to content

Commit

Permalink
Don't alternate the purpose of server.accept
Browse files Browse the repository at this point in the history
This originated as an attempt to fixed rails#2, rails#4, but it didn't help.
However, I think it's a good idea anyway in order to prevent the
alternation potentially getting out of sync.
  • Loading branch information
jonleighton committed Jan 1, 2013
1 parent 761df5e commit 3059f3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
27 changes: 15 additions & 12 deletions lib/spring.rb
Expand Up @@ -52,30 +52,33 @@ def boot_server
def run(args)
boot_server unless server_running?

socket = UNIXSocket.open(env.socket_name)
socket.write rails_env_for(args.first)
socket.close
application, client = UNIXSocket.pair

socket = UNIXSocket.open(env.socket_name)
server = UNIXSocket.open(env.socket_name)
server.send_io client
server.write rails_env_for(args.first)
server.close

socket.send_io STDOUT
socket.send_io STDERR
socket.send_io stdin_slave
client.close

socket.puts args.length
application.send_io STDOUT
application.send_io STDERR
application.send_io stdin_slave

application.puts args.length

args.each do |arg|
socket.puts arg.length
socket.write arg
application.puts arg.length
application.write arg
end

# FIXME: receive exit status from server
socket.read
application.read
true
rescue Errno::ECONNRESET
false
ensure
socket.close if socket
application.close if application
end

private
Expand Down
9 changes: 8 additions & 1 deletion lib/spring/server.rb
Expand Up @@ -25,7 +25,14 @@ def boot
write_pidfile

server = UNIXServer.open(env.socket_name)
loop { @applications[server.accept.read].run server.accept }
loop { serve server.accept }
end

def serve(client)
app_client = client.recv_io
rails_env = client.read

@applications[rails_env].run app_client
end

def set_exit_hook
Expand Down

0 comments on commit 3059f3f

Please sign in to comment.