summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ext/socket/lib/socket.rb17
2 files changed, 18 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 335b467..5d19e8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index f538295..4f2e729 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.