diff --git a/src/ipc/context.cr b/src/ipc/context.cr index 1b94a4a..28ed66a 100644 --- a/src/ipc/context.cr +++ b/src/ipc/context.cr @@ -130,11 +130,6 @@ class IPC::Context pointerof(@context) end - # sanitizer - def fd - @connection.fd - end - def close return if @closed r = LibIPC.ipc_close_all(self.pointer) diff --git a/tests/pongc.cr b/tests/pongc.cr index 509c301..4518597 100644 --- a/tests/pongc.cr +++ b/tests/pongc.cr @@ -1,6 +1,54 @@ require "../src/ipc.cr" -client = IPC::Client.new "pong" +class CLI + class_property service_name = "pong" + class_property message : String? = nil + class_property type = 1 + class_property user_type = 42 + class_property verbosity = 1 + class_property rounds = 1 +end + +OptionParser.parse do |parser| + parser.on "-s service_name", "--service-name service_name", "URI" do |optsn| + CLI.service_name = optsn + 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 + + parser.on "-t message_type", + "--type message_type", + "(internal) message type." do |opt| + CLI.type = opt.to_i + end + + parser.on "-u user_message_type", + "--user-type user_message_type", + "Message type." do |opt| + CLI.user_type = opt.to_i + end + + + parser.on "-r rounds", "--rounds count", "Number of messages sent." do |opt| + CLI.rounds = opt.to_i + end + + parser.on "-m message", "--message m", "Message to sent." do |opt| + CLI.message = opt + end + + parser.on "-h", "--help", "Show this help" do + puts parser + exit 0 + end +end + + +client = IPC::Client.new service_name +client.base_timer = 30_000 # 30 seconds +client.timer = 30_000 # 30 seconds server_fd = client.server_fd @@ -9,12 +57,22 @@ if server_fd.nil? exit 1 end -message = IPC::Message.new server_fd, 1, 42.to_u8, "salut ça va ?" +def info(message : String) + puts message unless CLI.verbosity +end + +message = IPC::Message.new server_fd, CLI.type.to_u8, CLI.user_type.to_u8, CLI.message client.send message +client << 0 client.loop do |event| case event + when IPC::Event::ExtraSocket + info "reading on #{event.fd}" + if event.fd == 0 + puts "reading on STDIN" + end when IPC::Event::MessageReceived puts "\033[32mthere is a message\033[00m" puts event.message.to_s