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_recv): extracted from

Socket.udp_server_loop_on.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-10-08 15:01:57 +00:00
parent 866c79e2de
commit abd31dc2ad
2 changed files with 47 additions and 19 deletions

View file

@ -1,3 +1,8 @@
Fri Oct 9 00:01:17 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/lib/socket.rb (Socket.udp_server_recv): extracted from
Socket.udp_server_loop_on.
Thu Oct 8 05:45:14 2009 NARUSE, Yui <naruse@ruby-lang.org>
* tool/enc-unicode.rb: parse range notation of UnicodeData.txt.

View file

@ -553,18 +553,26 @@ class Socket
end
# :call-seq:
# Socket.udp_server_loop_on(sockets) {|msg, msg_src| ... }
# Socket.udp_server_recv(sockets) {|msg, msg_src| ... }
#
# Run UDP/IP server loop on the given sockets.
# Receive UDP/IP packets from the given _sockets_.
# For each packet received, the block is called.
#
# The return value of Socket.udp_server_sockets is appropriate for the argument.
# The block receives _msg_ and _msg_src_.
# _msg_ is a string which is the payload of the received packet.
# _msg_src_ is a Socket::UDPSource object which is used for reply.
#
# It calls the block for each message received.
# Socket.udp_server_loop can be implemented using this method as follows.
#
def self.udp_server_loop_on(sockets) # :yield: msg, msg_src
loop {
readable, _, _ = IO.select(sockets)
readable.each {|r|
# udp_server_sockets(host, port) {|sockets|
# loop {
# readable, _, _ = IO.select(sockets)
# udp_server_recv(readable) {|msg, msg_src| ... }
# }
# }
#
def self.udp_server_recv(sockets)
sockets.each {|r|
begin
msg, sender_addrinfo, rflags, *controls = r.recvmsg_nonblock
rescue IO::WaitReadable
@ -582,6 +590,21 @@ class Socket
}
end
}
end
# :call-seq:
# Socket.udp_server_loop_on(sockets) {|msg, msg_src| ... }
#
# Run UDP/IP server loop on the given sockets.
#
# The return value of Socket.udp_server_sockets is appropriate for the argument.
#
# It calls the block for each message received.
#
def self.udp_server_loop_on(sockets, &b) # :yield: msg, msg_src
loop {
readable, _, _ = IO.select(sockets)
udp_server_recv(sockets, &b)
}
end