Skip to content

Commit

Permalink
alias sock for get_sockname (and use it in http_parser bind same exam…
Browse files Browse the repository at this point in the history
…ple)
  • Loading branch information
kostya committed Aug 25, 2012
1 parent cc3b692 commit 8392022
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/http_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/em-proxy/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def peer
@peer ||= peername ? Socket.unpack_sockaddr_in(peername).reverse : nil
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
#
Expand Down

0 comments on commit 8392022

Please sign in to comment.