diff --git a/libipc.h b/libipc.h index eb676e8..ed639d7 100644 --- a/libipc.h +++ b/libipc.h @@ -106,6 +106,7 @@ int ipc_add_switch (void* ctx, int fd1, int fd2); // 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. int ipc_set_switch_callbacks (void* ctx, int fd , char (*in (int orig, char *payload, size_t *mlen)) , char (*out(int dest, const char *payload, size_t mlen))); diff --git a/src/bindings.zig b/src/bindings.zig index cca83bc..2683bbf 100644 --- a/src/bindings.zig +++ b/src/bindings.zig @@ -152,8 +152,8 @@ export fn ipc_add_switch(ctx: *Context, fd1: i32, fd2: i32) callconv(.C) i32 { } export fn ipc_set_switch_callbacks(ctx: *Context, fd: i32, - in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, - out: *const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) callconv(.C) i32 { + in: ?*const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, + out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) callconv(.C) i32 { ctx.set_switch_callbacks(fd, in, out) catch return -1; return 0; } diff --git a/src/context.zig b/src/context.zig index 734c5ae..cdcb81e 100644 --- a/src/context.zig +++ b/src/context.zig @@ -317,8 +317,8 @@ pub const Context = struct { } pub fn set_switch_callbacks(self: *Self, fd: i32, - in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, - out: *const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void { + in: ?*const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, + out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void { try self.switchdb.set_callbacks(fd, in, out); } diff --git a/src/switch.zig b/src/switch.zig index 203d310..b337def 100644 --- a/src/switch.zig +++ b/src/switch.zig @@ -65,11 +65,11 @@ pub const SwitchDB = struct { } pub fn set_callbacks(self: *Self, fd: i32, - in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, - out: *const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void { + in: ?*const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8, + out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void { var managedconnection = self.db.get(fd) orelse return error.unregisteredFD; - managedconnection.in = in; - managedconnection.out = out; + if (in) |f| { managedconnection.in = f; } + if (out) |f| { managedconnection.out = f; } try self.db.put(fd, managedconnection); }