Class: NFS::SUNRPC::UDPServer
- Defined in:
- lib/nfs/sunrpc/udp_server.rb
Constant Summary collapse
- UDPRecvMTU =
10000
Instance Method Summary collapse
-
#initialize(programs, port = nil, host = '127.0.0.1') ⇒ UDPServer
constructor
A new instance of UDPServer.
Methods inherited from Server
#host, #join, #port, #shutdown, #start
Constructor Details
#initialize(programs, port = nil, host = '127.0.0.1') ⇒ UDPServer
Returns a new instance of UDPServer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nfs/sunrpc/udp_server.rb', line 9 def initialize(programs, port = nil, host = '127.0.0.1') @socket = UDPSocket.open @socket.bind(host, port) socketmutex = Mutex.new @programs = hash_programs(programs) @thread = Thread.new do loop do request = @socket.recvfrom(UDPRecvMTU) data = request[0] port = request[1][1] host = request[1][3] Thread.new do result = run_procedure(data) if !result.nil? socketmutex.synchronize do @socket.send(result, 0, host, port) end end end end end if block_given? begin yield(self) ensure shutdown end end end |