Class: Celluloid::IO::UDPSocket

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/celluloid/io/udp_socket.rb

Overview

UDPSockets with combined blocking and evented support

Instance Method Summary collapse

Constructor Details

#initialize(address_family = ::Socket::AF_INET) ⇒ UDPSocket

Returns a new instance of UDPSocket


8
9
10
# File 'lib/celluloid/io/udp_socket.rb', line 8

def initialize(address_family = ::Socket::AF_INET)
  @socket = ::UDPSocket.new(address_family)
end

Instance Method Details

#recvfrom(maxlen, flags = nil) ⇒ 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.


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/celluloid/io/udp_socket.rb', line 19

def recvfrom(maxlen, flags = nil)
  begin
    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

#to_ioObject


33
# File 'lib/celluloid/io/udp_socket.rb', line 33

def to_io; @socket; end

#wait_readableObject

Wait until the socket is readable


13
# File 'lib/celluloid/io/udp_socket.rb', line 13

def wait_readable; Celluloid::IO.wait_readable(self); end