1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/lib/socket.rb (Socket.udp_server_sockets): call the block

if given.  close the sockets when the block exits.
  (Socket.udp_server_loop): use udp_server_sockets in block form.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-02-11 08:39:57 +00:00
parent b9d2a43990
commit 83eddaad27
2 changed files with 18 additions and 5 deletions

View file

@ -1,3 +1,9 @@
Wed Feb 11 17:37:41 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/lib/socket.rb (Socket.udp_server_sockets): call the block
if given. close the sockets when the block exits.
(Socket.udp_server_loop): use udp_server_sockets in block form.
Wed Feb 11 17:34:16 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/lib/socket.rb (Socket.tcp_server_sockets): call the block

View file

@ -493,7 +493,15 @@ class Socket
end
}
sockets
if block_given?
begin
yield sockets
ensure
sockets.each {|s| s.close if !s.closed? } if sockets
end
else
sockets
end
end
# :call-seq:
@ -550,10 +558,9 @@ class Socket
# }
#
def self.udp_server_loop(host=nil, port, &b) # :yield: message, message_source
sockets = udp_server_sockets(host, port)
udp_server_loop_on(sockets, &b)
ensure
sockets.each {|s| s.close if !s.closed? } if sockets
udp_server_sockets(host, port) {|sockets|
udp_server_loop_on(sockets, &b)
}
end
# UDP address information used by Socket.udp_server_loop.