Obsolete
/
libipc-old
Archived
3
0
Fork 0

Grooming.

master
Philippe Pittoli 2022-12-29 10:12:40 +01:00
parent 98eede6814
commit de1d221881
2 changed files with 28 additions and 13 deletions

View File

@ -247,9 +247,9 @@ pub const Context = struct {
var count: usize = undefined; var count: usize = undefined;
// print("Let's wait for an event (either stdin or unix socket)\n", .{}); // print("Let's wait for an event (either stdin or unix socket)\n", .{});
print("fds: {any}\n", .{self.pollfd.items}); // print("fds: {any}\n", .{self.pollfd.items});
count = try os.poll(self.pollfd.items, wait_duration); count = try os.poll(self.pollfd.items, wait_duration);
print("fds NOW: {any}\n", .{self.pollfd.items}); // print("fds NOW: {any}\n", .{self.pollfd.items});
if (count < 0) { if (count < 0) {
print("there is a problem: poll < 0\n", .{}); print("there is a problem: poll < 0\n", .{});
@ -259,7 +259,7 @@ pub const Context = struct {
var duration = timer.read() / 1000000; // ns -> ms var duration = timer.read() / 1000000; // ns -> ms
if (count == 0) { if (count == 0) {
print("wait: configured {} measured {}\n", .{wait_duration, duration}); // print("wait: configured {} measured {}\n", .{wait_duration, duration});
if (duration >= wait_duration) { if (duration >= wait_duration) {
current_event = Event.init(Event.Type.TIMER, 0, 0, null); current_event = Event.init(Event.Type.TIMER, 0, 0, null);
} }

View File

@ -9,7 +9,8 @@ const print = std.debug.print;
const testing = std.testing; const testing = std.testing;
const print_eq = @import("./util.zig").print_eq; const print_eq = @import("./util.zig").print_eq;
// TODO: file descriptors should have a specific type (but i32 is used in std.net...). // TODO: standard library is unecessary complex regarding networking.
// Should libipc drop it and use plain old file descriptors instead?
// TODO: path => std.XXX.YYY, not simple [] const u8 // TODO: path => std.XXX.YYY, not simple [] const u8
@ -38,48 +39,62 @@ fn create_service() !void {
// TODO: signal handler, to quit when asked // TODO: signal handler, to quit when asked
var some_event: ipc.Event = undefined; var some_event: ipc.Event = undefined;
ctx.timer = 2000; // 1 second ctx.timer = 2000; // 2 seconds
while(true) { while(true) {
some_event = try ctx.wait_event(); some_event = try ctx.wait_event();
switch (some_event.t) { switch (some_event.t) {
.CONNECTION => {
print("New connection: {}!\n", .{some_event});
},
.TIMER => { .TIMER => {
print("Timer!\n", .{}); print("Timer!\n", .{});
}, },
.CONNECTION => {
print("New connection: {} so far!\n", .{ctx.pollfd.items.len});
},
.DISCONNECTION => {
print("User {} disconnected, {} remainaing.\n"
, .{some_event.origin, ctx.pollfd.items.len});
},
.EXTERNAL => { .EXTERNAL => {
print("Message received from a non IPC socket.\n", .{}); print("Message received from a non IPC socket.\n", .{});
print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{}); print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{});
break; break;
}, },
.SWITCH => { .SWITCH => {
print("Message to send to a corresponding fd.\n", .{}); print("Message to send to a corresponding fd.\n", .{});
print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{}); print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{});
break; break;
}, },
.DISCONNECTION => {
print("User disconnected.\n", .{});
},
.MESSAGE => { .MESSAGE => {
print("New message. {}\n", .{some_event});
print("Let's echo, once\n", .{});
if (some_event.m) |m| { if (some_event.m) |m| {
print("New message: {}\n", .{m});
print("Let's echo it...\n", .{});
try ctx.schedule(m); try ctx.schedule(m);
} }
else {
print("Error while receiving new message.\n", .{});
print("Ignoring...\n", .{});
}
}, },
.LOOKUP => { .LOOKUP => {
print("Client asking for a service through ipcd.\n", .{}); print("Client asking for a service through ipcd.\n", .{});
print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{}); print("NOT IMPLEMENTED, YET. It's a suicide, then.\n", .{});
break; break;
}, },
.TX => { .TX => {
print("Message sent.\n", .{}); print("Message sent.\n", .{});
}, },
.NOT_SET => { .NOT_SET => {
print("Event type not set. Something is wrong, let's suicide.\n", .{}); print("Event type not set. Something is wrong, let's suicide.\n", .{});
break; break;
}, },
.ERROR => { .ERROR => {
print("A problem occured, event: {}, let's suicide\n", .{some_event}); print("A problem occured, event: {}, let's suicide\n", .{some_event});
break; break;