Class: MessagePack::RPC::UDPTransport::BasicSocket

Inherits:
Cool.io::IOWatcher
  • Object
show all
Includes:
MessageReceiver
Defined in:
lib/msgpack/rpc/transport/udp.rb

Constant Summary collapse

HAVE_DNRL =
UDPSocket.public_instance_methods.include?(:do_not_reverse_lookup)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MessageReceiver

#on_message

Constructor Details

#initialize(io) ⇒ BasicSocket

Returns a new instance of BasicSocket.



34
35
36
37
38
# File 'lib/msgpack/rpc/transport/udp.rb', line 34

def initialize(io)
	io.do_not_reverse_lookup = true if HAVE_DNRL
	super(io)
	@io = io
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



40
41
42
# File 'lib/msgpack/rpc/transport/udp.rb', line 40

def io
  @io
end

Instance Method Details

#on_readableObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/msgpack/rpc/transport/udp.rb', line 42

def on_readable
	begin
		data, addr = @io.recvfrom(64*1024) # FIXME buffer size
	rescue Errno::EAGAIN
		return
	end

	# FIXME multiple objects in one message
	obj = MessagePack.unpack(data)
	on_message(obj, addr)
rescue
	# FIXME log
	return
end