Permalink
Browse files

Merge pull request #27 from kostya/master

alias sock for get_sockname (and use it in http_parser bind same example)
  • Loading branch information...
2 parents cc3b692 + 93656db commit 23457ddf7d013a2e2c5a04f1bd5725dc82982f0f @igrigorik committed Aug 25, 2012
Showing with 15 additions and 3 deletions.
  1. +1 −1 examples/http_proxy.rb
  2. +14 −2 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
16 lib/em-proxy/connection.rb
@@ -57,8 +57,20 @@ def server(name, opts)
# [ip, port] of the connected client
#
def peer
- peername = get_peername
- @peer ||= peername ? Socket.unpack_sockaddr_in(peername).reverse : nil
+ @peer ||= begin
+ peername = get_peername
+ peername ? Socket.unpack_sockaddr_in(peername).reverse : nil
+ end
+ end
+
+ #
+ # [ip, port] of the local server connect
+ #
+ def sock
+ @sock ||= begin
+ sockname = get_sockname
+ sockname ? Socket.unpack_sockaddr_in(sockname).reverse : nil
+ end
end
#

0 comments on commit 23457dd

Please sign in to comment.