Sha256: 63fd377f674c640e02d55ee74a77f0d2fe587709e0c38ecb976aa5f34e56c7e9

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

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

      def initialize
        @socket = ::UDPSocket.new
      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.15.0 lib/celluloid/io/udp_socket.rb
celluloid-io-0.15.0.pre2 lib/celluloid/io/udp_socket.rb
celluloid-io-0.15.0.pre lib/celluloid/io/udp_socket.rb
celluloid-io-0.14.1 lib/celluloid/io/udp_socket.rb
celluloid-io-0.14.0 lib/celluloid/io/udp_socket.rb
celluloid-io-0.14.0.pre lib/celluloid/io/udp_socket.rb