Switch: callbacks can be set to "NULL" to keep default operations.
This commit is contained in:
parent
45614deacb
commit
f59eb58e0b
4 changed files with 9 additions and 8 deletions
1
libipc.h
1
libipc.h
|
@ -106,6 +106,7 @@ int ipc_add_switch (void* ctx, int fd1, int fd2);
|
||||||
|
|
||||||
// Set IO callbacks for a file descriptor.
|
// Set IO callbacks for a file descriptor.
|
||||||
// Returned "char" is a cb_event_types enum.
|
// 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
|
int ipc_set_switch_callbacks (void* ctx, int fd
|
||||||
, char (*in (int orig, char *payload, size_t *mlen))
|
, char (*in (int orig, char *payload, size_t *mlen))
|
||||||
, char (*out(int dest, const char *payload, size_t mlen)));
|
, char (*out(int dest, const char *payload, size_t mlen)));
|
||||||
|
|
|
@ -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,
|
export fn ipc_set_switch_callbacks(ctx: *Context, fd: i32,
|
||||||
in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8,
|
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 {
|
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;
|
ctx.set_switch_callbacks(fd, in, out) catch return -1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,8 +317,8 @@ pub const Context = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_switch_callbacks(self: *Self, fd: i32,
|
pub fn set_switch_callbacks(self: *Self, fd: i32,
|
||||||
in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8,
|
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 {
|
out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void {
|
||||||
try self.switchdb.set_callbacks(fd, in, out);
|
try self.switchdb.set_callbacks(fd, in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,11 @@ pub const SwitchDB = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_callbacks(self: *Self, fd: i32,
|
pub fn set_callbacks(self: *Self, fd: i32,
|
||||||
in: *const fn (origin: i32, mcontent: [*]u8, mlen: *usize) callconv(.C) u8,
|
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 {
|
out: ?*const fn (origin: i32, mcontent: [*]const u8, mlen: usize) callconv(.C) u8) !void {
|
||||||
var managedconnection = self.db.get(fd) orelse return error.unregisteredFD;
|
var managedconnection = self.db.get(fd) orelse return error.unregisteredFD;
|
||||||
managedconnection.in = in;
|
if (in) |f| { managedconnection.in = f; }
|
||||||
managedconnection.out = out;
|
if (out) |f| { managedconnection.out = f; }
|
||||||
try self.db.put(fd, managedconnection);
|
try self.db.put(fd, managedconnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue