Warn if can't attach to websocket port

This commit is contained in:
Michael Nutt 2010-09-16 02:34:11 -04:00
parent ef2e393ac8
commit 46a83324ab

View file

@ -9,18 +9,26 @@ require "lib/diaspora/websocket"
EM.next_tick { EM.next_tick {
Diaspora::WebSocket.initialize_channels Diaspora::WebSocket.initialize_channels
EventMachine::WebSocket.start( begin
:host => "0.0.0.0", EventMachine::WebSocket.start(
:port => APP_CONFIG[:socket_port], :host => "0.0.0.0",
:debug =>APP_CONFIG[:socket_debug]) do |ws| :port => APP_CONFIG[:socket_port],
ws.onopen { :debug =>APP_CONFIG[:socket_debug]) do |ws|
ws.onopen {
sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws)
ws.onmessage { |msg| SocketsController.new.incoming(msg) } ws.onmessage { |msg| SocketsController.new.incoming(msg) }
ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) }
} }
end
rescue RuntimeError => e
if e.message =~ /no acceptor/
raise RuntimeError, "Could not listen on port #{APP_CONFIG[:socket_port]}, perhaps another process is already using it?"
else
raise
end
end end
} }