Skip to content
Browse files

alias sock for get_sockname (and use it in http_parser bind same exam…

…ple)
  • Loading branch information...
1 parent cc3b692 commit 8392022da9de4075b176a94d24a5f304d5c5feac @kostya kostya committed Aug 23, 2012
Showing with 9 additions and 1 deletion.
  1. +1 −1 examples/http_proxy.rb
  2. +8 −0 lib/em-proxy/connection.rb
View
2 examples/http_proxy.rb
@@ -18,7 +18,7 @@
puts "New session: #{session} (#{h.inspect})"
host, port = h['Host'].split(':')
- conn.server session, :host => host, :port => (port || 80) #, :bind_host => conn.peer[0] - # for bind ip
+ conn.server session, :host => host, :port => (port || 80) #, :bind_host => conn.sock[0] - # for bind ip
conn.relay_to_servers @buffer
View
8 lib/em-proxy/connection.rb
@@ -62,6 +62,14 @@ def peer
end
#
+ # [ip, port] of the local server connect
+ #
+ def sock
+ sockname = get_sockname
+ @sock ||= sockname ? Socket.unpack_sockaddr_in(sockname).reverse : nil
+ end
+
+ #
# relay data from backend server to client
#
def relay_from_backend(name, data)

0 comments on commit 8392022

Please sign in to comment.
Something went wrong with that request. Please try again.