fixing client init
This commit is contained in:
parent
3665fe0eac
commit
f4c9ccad60
@ -2,6 +2,23 @@
|
|||||||
class IPC::Client < IPC::Context
|
class IPC::Client < IPC::Context
|
||||||
property server_fd : Int32?
|
property server_fd : Int32?
|
||||||
|
|
||||||
|
# By default, this is a client.
|
||||||
|
def initialize(service_name : String)
|
||||||
|
super()
|
||||||
|
serverfd = 0
|
||||||
|
|
||||||
|
r = LibIPC.ipc_connection(self.pointer, service_name, pointerof(serverfd))
|
||||||
|
if r.error_code != 0
|
||||||
|
m = String.new r.error_message.to_slice
|
||||||
|
raise Exception.new "error during connection establishment: #{m}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@server_fd = serverfd
|
||||||
|
|
||||||
|
# Very important as there are filesystem side-effects.
|
||||||
|
at_exit { close }
|
||||||
|
end
|
||||||
|
|
||||||
def read
|
def read
|
||||||
unless (fd = @server_fd).nil?
|
unless (fd = @server_fd).nil?
|
||||||
message = LibIPC::Message.new
|
message = LibIPC::Message.new
|
||||||
@ -15,21 +32,4 @@ class IPC::Client < IPC::Context
|
|||||||
raise "Client not connected to a server"
|
raise "Client not connected to a server"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# By default, this is a client.
|
|
||||||
def initialize(service_name : String)
|
|
||||||
super()
|
|
||||||
serverfd = 0
|
|
||||||
|
|
||||||
r = LibIPC.ipc_connection(self.pointer, service_name, pointerof(serverfd))
|
|
||||||
if r.error_code != 0
|
|
||||||
m = String.new r.error_message.to_slice
|
|
||||||
raise Exception.new "error during connection establishment: #{m}"
|
|
||||||
end
|
|
||||||
|
|
||||||
@server_fd = server_fd
|
|
||||||
|
|
||||||
# Very important as there are filesystem side-effects.
|
|
||||||
at_exit { close }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,7 @@ client = IPC::Client.new "pong"
|
|||||||
server_fd = client.server_fd
|
server_fd = client.server_fd
|
||||||
|
|
||||||
if server_fd.nil?
|
if server_fd.nil?
|
||||||
|
puts "there is no server_fd!!"
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user