Sha256: aebe7db637479520402e13eada54beadb52cb327b4e9ef1660b93df90228189e

Contents?: true

Size: 1.12 KB

Versions: 6

Compression:

Stored size: 1.12 KB

Contents

module Celluloid
  module IO
    # UDPSockets with combined blocking and evented support
    class UDPSocket
      extend Forwardable
      def_delegators :@socket, :addr, :bind, :connect, :send, :recvfrom_nonblock, :close, :closed?

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

      # Wait until the socket is readable
      def wait_readable; Celluloid::IO.wait_readable(self); end

      # 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.
      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

      def to_io; @socket; end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
celluloid-io-0.17.2 lib/celluloid/io/udp_socket.rb
celluloid-io-0.17.1 lib/celluloid/io/udp_socket.rb
celluloid-io-0.17.0 lib/celluloid/io/udp_socket.rb
celluloid-io-0.16.5.pre0 lib/celluloid/io/udp_socket.rb
celluloid-io-0.16.2 lib/celluloid/io/udp_socket.rb
celluloid-io-0.16.1 lib/celluloid/io/udp_socket.rb