diff --git a/shard.yml b/shard.yml index 4f3a0fc..0a58fac 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: ipc -version: 0.1.2 +version: 0.2.0 authors: - Philippe Pittoli @@ -15,6 +15,6 @@ dependencies: branch: master libraries: - libipc: ">= 0.1.2" + libipc: ">= 0.2.0" license: ISC diff --git a/src/bindings.cr b/src/bindings.cr index dea5128..7127fc5 100644 --- a/src/bindings.cr +++ b/src/bindings.cr @@ -15,7 +15,7 @@ lib LibIPC fun init = ipc_context_init(Void**) : LibC::Int fun deinit = ipc_context_deinit(Void**) : Void - fun service_init = ipc_service_init(Void*, LibC::Int*, LibC::Char*, LibC::UInt16T) : LibC::Int + fun service_init = ipc_service_init( Void*, LibC::Int*, LibC::Char*, LibC::UInt16T) : LibC::Int fun connect_service = ipc_connect_service(Void*, LibC::Int*, LibC::Char*, LibC::UInt16T) : LibC::Int # Context EventType index serverfd newclientfd buffer buflen @@ -34,4 +34,18 @@ lib LibIPC fun close = ipc_close(Void*, LibC::UInt64T) : LibC::Int fun close_fd = ipc_close_fd(Void*, LibC::Int) : LibC::Int fun close_all = ipc_close_all(Void*) : LibC::Int + + # Add a new external file descriptor. + # LibIPC won't automatically read the content. + fun external = ipc_add_external (Void*, LibC::Int) : LibC::Int + + # Add a new switch (messages are automatically exchanged between these two file descriptors). + fun add_switch = ipc_add_switch (Void*, LibC::Int, LibC::Int) : LibC::Int + + # Set IO callbacks for a file descriptor. + # Returned "char" is a cb_event_types enum. + # One of the callbacks can be "NULL" to keep the default callback, thus changing only input or output operations. + fun switch_callbacks = ipc_set_switch_callbacks (Void*, LibC::Int, + (LibC::Int, LibC::Char*, LibC::UInt64T* -> LibC::Char), + (LibC::Int, LibC::Char*, LibC::UInt64T -> LibC::Char)); end diff --git a/src/high-level-bindings.cr b/src/high-level-bindings.cr index 50aa65f..786fd13 100644 --- a/src/high-level-bindings.cr +++ b/src/high-level-bindings.cr @@ -108,6 +108,26 @@ class IPC end end + def external(fd : LibC::Int) + if LibIPC.external(@context, fd) != 0 + raise "Oh noes, 'external' iz brkn" + end + end + + def add_switch(fd1 : LibC::Int, fd2 : LibC::Int) + if LibIPC.add_switch(@context, fd1, fd2) != 0 + raise "Oh noes, 'add_switch' iz brkn" + end + end + + def switch_callbacks(fd : LibC::Int, + fn_in : (LibC::Int, LibC::Char*, LibC::UInt64T* -> LibC::Char), + fn_out : (LibC::Int, LibC::Char*, LibC::UInt64T -> LibC::Char)) + if LibIPC.switch_callbacks(@context, fd, fn_in, fn_out) != 0 + raise "Oh noes, 'switch_callbacks' iz brkn" + end + end + def wait : IPC::Event eventtype : UInt8 = 0 index : LibC::UInt64T = 0