summaryrefslogtreecommitdiff
path: root/ext/socket/lib/socket.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 08:39:57 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-11 08:39:57 +0000
commit83eddaad27990c840ac186cc6cb8941aeb356caf (patch)
tree1a1432cd9a9c9b86a074a04fe6b7af172dcba1fe /ext/socket/lib/socket.rb
parentb9d2a4399065197d5a42b78b622ac456ae02d631 (diff)
* 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
Diffstat (limited to 'ext/socket/lib/socket.rb')
-rw-r--r--ext/socket/lib/socket.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index f5382950a9a..4f2e7294ace 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -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.