blah
parent
17048dbd45
commit
725b23e4e5
|
@ -58,10 +58,10 @@ def main
|
|||
exit 1
|
||||
end
|
||||
|
||||
# Listening on STDIN.
|
||||
client << 0
|
||||
|
||||
client.loop do |event|
|
||||
puts "CLIENT LOOP"
|
||||
case event
|
||||
when IPC::Event::ExtraSocket
|
||||
puts "extra socket fd #{event.fd}"
|
||||
|
@ -71,7 +71,7 @@ def main
|
|||
end
|
||||
|
||||
mstr = if CLI.message.nil?
|
||||
if event.fd == 0 STDIN.gets_to_end else "coucou" end
|
||||
if event.fd == 0 STDIN.gets || "STDIN failed!" else "coucou" end
|
||||
else
|
||||
CLI.message.not_nil!
|
||||
end
|
||||
|
@ -83,12 +83,18 @@ def main
|
|||
|
||||
message.fd = server_fd.not_nil!
|
||||
|
||||
client.send message
|
||||
CLI.rounds.times do |i|
|
||||
client.send message
|
||||
end
|
||||
when IPC::Event::MessageReceived
|
||||
puts "\033[32mthere is a message\033[00m"
|
||||
puts event.message.to_s
|
||||
client.close
|
||||
exit
|
||||
info "new message from #{event.fd}: #{event.message.to_s}"
|
||||
when IPC::Event::Disconnection
|
||||
info "Disconnection from #{event.fd}"
|
||||
if event.fd == 0
|
||||
client.remove_fd 0
|
||||
end
|
||||
else
|
||||
info "unhandled event: #{event.class}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ require "./prints.cr"
|
|||
class CLI
|
||||
class_property service_name = "pong"
|
||||
class_property verbosity = 1
|
||||
class_property timer = 30_000
|
||||
class_property no_response = false
|
||||
end
|
||||
|
||||
|
@ -17,6 +18,11 @@ OptionParser.parse do |parser|
|
|||
CLI.no_response = true
|
||||
end
|
||||
|
||||
parser.on "-t timer", "--timer ms", "Timer in ms. Default: 30 000" do |optsn|
|
||||
CLI.timer = optsn.to_i
|
||||
end
|
||||
|
||||
|
||||
parser.on "-v verbosity", "--verbosity verbosity", "Verbosity (0 = nothing is printed, 1 = only events, 2 = events and messages). Default: 1" do |optsn|
|
||||
CLI.verbosity = optsn.to_i
|
||||
end
|
||||
|
@ -29,10 +35,11 @@ end
|
|||
|
||||
def main
|
||||
service = IPC::Server.new CLI.service_name
|
||||
service.base_timer = 30_000 # 30 seconds
|
||||
service.timer = 30_000 # 30 seconds
|
||||
service.base_timer = CLI.timer # default: 30 seconds
|
||||
service.timer = CLI.timer # default: 30 seconds
|
||||
|
||||
service.loop do |event|
|
||||
service.pp
|
||||
case event
|
||||
when IPC::Event::Timer
|
||||
info "IPC::Event::Timer"
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require "./colors"
|
||||
|
||||
def important(message : String)
|
||||
puts "#{CRED}#{message}#{CRESET}" unless CLI.verbosity > 0
|
||||
puts "#{CRED}#{message}#{CRESET}" if CLI.verbosity > 0
|
||||
end
|
||||
|
||||
def info(message : String)
|
||||
puts "#{CGREEN}#{message}#{CRESET}" unless CLI.verbosity > 1
|
||||
puts "#{CGREEN}#{message}#{CRESET}" if CLI.verbosity > 1
|
||||
end
|
||||
|
||||
def debug(message : String)
|
||||
puts "#{CBLUE}#{message}#{CRESET}" unless CLI.verbosity > 2
|
||||
puts "#{CBLUE}#{message}#{CRESET}" if CLI.verbosity > 2
|
||||
end
|
||||
|
|
Reference in New Issue