Proxy: removing keepalive messages, and some code split.
parent
0c81234c0d
commit
b76453a123
|
@ -12,6 +12,7 @@ module IPCProxy
|
||||||
@@proxy_name = ARGV[1] if ARGV.size >= 2
|
@@proxy_name = ARGV[1] if ARGV.size >= 2
|
||||||
|
|
||||||
puts "proxy named #{@@proxy_name} for service #{@@proxied_service}"
|
puts "proxy named #{@@proxy_name} for service #{@@proxied_service}"
|
||||||
|
puts "removing keepalive messages"
|
||||||
|
|
||||||
ipc_proxy = IPC.new()
|
ipc_proxy = IPC.new()
|
||||||
ipc_proxy.service_init @@proxy_name
|
ipc_proxy.service_init @@proxy_name
|
||||||
|
@ -66,36 +67,59 @@ module IPCProxy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def fn_input(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T*) : LibC::Char
|
def read_input(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T*) : LibC::Char
|
||||||
io = IO::FileDescriptor.new fd, close_on_finalize: false
|
io = IO::FileDescriptor.new fd, close_on_finalize: false
|
||||||
slice = Bytes.new buffer, buflen.value
|
slice = Bytes.new buffer, buflen.value
|
||||||
len = io.read slice
|
len = io.read slice
|
||||||
buflen.value = len.to_u64
|
buflen.value = len.to_u64
|
||||||
return 2_u8 if (len == 0)
|
return 2_u8 if (len == 0)
|
||||||
|
|
||||||
hexa = Hexa.new 50_000
|
|
||||||
bytes = Bytes.new buffer, buflen.value
|
|
||||||
puts hexa.dump "message received from #{fd}", bytes
|
|
||||||
|
|
||||||
0_u8
|
0_u8
|
||||||
rescue e
|
rescue e
|
||||||
puts "fn_input exception! #{e}"
|
puts "read_input exception! #{e}"
|
||||||
1_u8
|
1_u8
|
||||||
end
|
end
|
||||||
|
|
||||||
def fn_output(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T) : LibC::Char
|
def keepalive?(buffer : LibC::Char*) : Bool
|
||||||
|
return (buffer[4] == 250)
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_hexa(buffer : LibC::Char*, buflen : LibC::UInt64T, title : String)
|
||||||
hexa = Hexa.new 50_000
|
hexa = Hexa.new 50_000
|
||||||
bytes = Bytes.new buffer, buflen
|
bytes = Bytes.new buffer, buflen
|
||||||
puts hexa.dump "message to send to #{fd}", bytes
|
puts hexa.dump title, bytes
|
||||||
|
end
|
||||||
|
|
||||||
|
def fn_input(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T*) : LibC::Char
|
||||||
|
# First, get the content.
|
||||||
|
ret = read_input fd, buffer, buflen
|
||||||
|
return ret if ret != 0
|
||||||
|
|
||||||
|
# Second, is this a keepalive message?
|
||||||
|
return ret if keepalive? buffer
|
||||||
|
|
||||||
|
# Finally, print an hexadecimal presentation of the content.
|
||||||
|
print_hexa buffer, buflen.value, "message received from #{fd}"
|
||||||
|
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
|
||||||
|
def write_output(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T) : LibC::Char
|
||||||
slice = Bytes.new buffer, buflen
|
slice = Bytes.new buffer, buflen
|
||||||
io = IO::FileDescriptor.new fd, close_on_finalize: false
|
io = IO::FileDescriptor.new fd, close_on_finalize: false
|
||||||
io.write slice
|
io.write slice
|
||||||
io.flush
|
io.flush
|
||||||
0_u8
|
0_u8
|
||||||
rescue e
|
rescue e
|
||||||
puts "fn_output exception! #{e}"
|
puts "write_output exception! #{e}"
|
||||||
1_u8
|
1_u8
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fn_output(fd : LibC::Int, buffer : LibC::Char*, buflen : LibC::UInt64T) : LibC::Char
|
||||||
|
unless keepalive? buffer
|
||||||
|
print_hexa buffer, buflen, "message to send to #{fd}"
|
||||||
|
end
|
||||||
|
write_output fd, buffer, buflen
|
||||||
|
end
|
||||||
|
|
||||||
IPCProxy.start
|
IPCProxy.start
|
||||||
|
|
Loading…
Reference in New Issue