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