Pongd fixed.
This commit is contained in:
parent
dd9f94ae78
commit
17048dbd45
@ -2,21 +2,23 @@ require "option_parser"
|
|||||||
require "../src/ipc.cr"
|
require "../src/ipc.cr"
|
||||||
require "./prints.cr"
|
require "./prints.cr"
|
||||||
|
|
||||||
verbosity = 1
|
class CLI
|
||||||
service_name = "pong"
|
class_property service_name = "pong"
|
||||||
no_response = false
|
class_property verbosity = 1
|
||||||
|
class_property no_response = false
|
||||||
|
end
|
||||||
|
|
||||||
OptionParser.parse do |parser|
|
OptionParser.parse do |parser|
|
||||||
parser.on "-s service_name", "--service-name service_name", "URI" do |optsn|
|
parser.on "-s service_name", "--service-name service_name", "URI" do |optsn|
|
||||||
service_name = optsn
|
CLI.service_name = optsn
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "-n", "--no-response", "Do not provide any response back." do
|
parser.on "-n", "--no-response", "Do not provide any response back." do
|
||||||
no_response = true
|
CLI.no_response = true
|
||||||
end
|
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|
|
||||||
verbosity = optsn.to_i
|
CLI.verbosity = optsn.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
parser.on "-h", "--help", "Show this help" do
|
parser.on "-h", "--help", "Show this help" do
|
||||||
@ -25,7 +27,8 @@ OptionParser.parse do |parser|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
service = IPC::Server.new (service_name)
|
def main
|
||||||
|
service = IPC::Server.new CLI.service_name
|
||||||
service.base_timer = 30_000 # 30 seconds
|
service.base_timer = 30_000 # 30 seconds
|
||||||
service.timer = 30_000 # 30 seconds
|
service.timer = 30_000 # 30 seconds
|
||||||
|
|
||||||
@ -39,11 +42,9 @@ service.loop do |event|
|
|||||||
info "IPC::Event::Disconnection, client: #{event.fd}"
|
info "IPC::Event::Disconnection, client: #{event.fd}"
|
||||||
when IPC::Event::MessageSent
|
when IPC::Event::MessageSent
|
||||||
begin
|
begin
|
||||||
if verbosity >= 1
|
info "IPC::Event::MessageSent, client: #{event.fd}"
|
||||||
puts "#{CGREEN}IPC::Event::MessageSent#{CRESET}, client: #{event.fd}"
|
|
||||||
end
|
|
||||||
rescue e
|
rescue e
|
||||||
puts "#{CRED}#{e.message}#{CRESET}"
|
important "#{e.message}"
|
||||||
service.remove_fd event.fd
|
service.remove_fd event.fd
|
||||||
end
|
end
|
||||||
when IPC::Event::MessageReceived
|
when IPC::Event::MessageReceived
|
||||||
@ -51,7 +52,8 @@ service.loop do |event|
|
|||||||
info "IPC::Event::MessageReceived, client: #{event.fd}"
|
info "IPC::Event::MessageReceived, client: #{event.fd}"
|
||||||
m = String.new event.message.payload
|
m = String.new event.message.payload
|
||||||
debug "message type #{event.message.utype}: #{m}"
|
debug "message type #{event.message.utype}: #{m}"
|
||||||
unless no_response
|
|
||||||
|
unless CLI.no_response
|
||||||
service.send event.message
|
service.send event.message
|
||||||
debug "sending message..."
|
debug "sending message..."
|
||||||
end
|
end
|
||||||
@ -64,3 +66,6 @@ service.loop do |event|
|
|||||||
important "Exception: message #{event}"
|
important "Exception: message #{event}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
main
|
||||||
|
Reference in New Issue
Block a user