alias sock for get_sockname (and use it in http_parser bind same example) #27

Merged
merged 2 commits into from Aug 25, 2012
View
@@ -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
@@ -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
#