class NTP::Server::Control
Constants
- DEFAULT_PORT
Public Class Methods
new()
click to toggle source
# File lib/ntp/server/control.rb, line 72 def initialize @client_out = Fifo.new('ntp-mock-server-in', :w, :nowait) @client_in = Fifo.new('ntp-mock-server-out', :r, :nowait) end
Public Instance Methods
reset()
click to toggle source
# File lib/ntp/server/control.rb, line 54 def reset send_command('reset') end
restart()
click to toggle source
# File lib/ntp/server/control.rb, line 46 def restart [ stop, start ].join("\n") end
start(port = DEFAULT_PORT)
click to toggle source
# File lib/ntp/server/control.rb, line 17 def start port = DEFAULT_PORT fork do Process.setsid NTP::Server::Base.new(port || DEFAULT_PORT).start end read(@client_in, 5) end
status()
click to toggle source
# File lib/ntp/server/control.rb, line 11 def status send_command('status') status = read(@client_in) status || "not running" end
stop()
click to toggle source
# File lib/ntp/server/control.rb, line 25 def stop send_command('stop') s = true begin Timeout::timeout(5) do while s do send_command('status') s = read(@client_in) end end rescue Timeout::Error end if s "failed to stop: status #{s}" else "stopped" end end
time(time)
click to toggle source
# File lib/ntp/server/control.rb, line 50 def time time send_command("time #{time}") end
usage()
click to toggle source
# File lib/ntp/server/control.rb, line 7 def usage "Usage: ntp-mock-server [start|stop|restart|status|time <time>|reset]" end
Private Instance Methods
read(client_in, timeout = 1)
click to toggle source
# File lib/ntp/server/control.rb, line 65 def read client_in, timeout = 1 begin Timeout::timeout(timeout) { client_in.gets } rescue Timeout::Error end end
send_command(data)
click to toggle source
# File lib/ntp/server/control.rb, line 60 def send_command data @client_out.puts data @client_out.to_io.sync end