Class: Celluloid::IO::UDPSocket
- Extended by:
- Forwardable
- Defined in:
- lib/celluloid/io/udp_socket.rb
Overview
UDPSockets with combined blocking and evented support
Constant Summary
Constants inherited from Socket
Instance Method Summary collapse
-
#initialize(*args) ⇒ UDPSocket
constructor
A new instance of UDPSocket.
-
#recvfrom(maxlen, flags = 0) ⇒ Object
Receives up to maxlen bytes from socket.
-
#wait_readable ⇒ Object
Wait until the socket is readable.
Methods inherited from Socket
Constructor Details
#initialize(address_family) ⇒ UDPSocket #initialize(socket) ⇒ UDPSocket
Returns a new instance of UDPSocket.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/celluloid/io/udp_socket.rb', line 15 def initialize(*args) if args.first.kind_of? ::BasicSocket # socket socket = args.first fail ArgumentError, "wrong number of arguments (#{args.size} for 1)" if args.size != 1 fail ArgumentError, "wrong kind of socket (#{socket.class} for UDPSocket)" unless socket.kind_of? ::UDPSocket super(socket) else super(::UDPSocket.new(*args)) end end |
Instance Method Details
#recvfrom(maxlen, flags = 0) ⇒ Object
Receives up to maxlen bytes from socket. flags is zero or more of the MSG_ options. The first element of the results, mesg, is the data received. The second element, sender_addrinfo, contains protocol-specific address information of the sender.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/celluloid/io/udp_socket.rb', line 34 def recvfrom(maxlen, flags = 0) begin socket = to_io if socket.respond_to? :recvfrom_nonblock socket.recvfrom_nonblock(maxlen, flags) else # FIXME: hax for JRuby socket.recvfrom(maxlen, flags) end rescue ::IO::WaitReadable wait_readable retry end end |
#wait_readable ⇒ Object
Wait until the socket is readable
28 |
# File 'lib/celluloid/io/udp_socket.rb', line 28 def wait_readable; Celluloid::IO.wait_readable(self); end |