Obsolete
/
libipc-old
Archived
3
0
Fork 0

Less debug messages.

master
Philippe Pittoli 2023-01-11 16:30:08 +01:00
parent 28d7dd8fc2
commit ba6671d902
3 changed files with 12 additions and 18 deletions

View File

@ -284,8 +284,6 @@ pub const Context = struct {
self.connections.items[index_destinataire].t = Connection.Type.SWITCHED; self.connections.items[index_destinataire].t = Connection.Type.SWITCHED;
try self.switchdb.add_switch(fd1,fd2); try self.switchdb.add_switch(fd1,fd2);
print("ADD SWITCH\n", .{});
print("self: {}\n", .{self});
} }
pub fn set_switch_callbacks(self: *Self, fd: i32 pub fn set_switch_callbacks(self: *Self, fd: i32

View File

@ -16,6 +16,7 @@ const native_os = builtin.target.os.tag;
const print = std.debug.print; 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;
const URI = @import("./util.zig").URI;
// Standard library is unecessary complex regarding networking. // Standard library is unecessary complex regarding networking.
// libipc drops it and uses plain old file descriptors instead. // libipc drops it and uses plain old file descriptors instead.
@ -135,33 +136,28 @@ fn create_service() !void {
print("ERROR: no target in: {s}\n", .{next}); print("ERROR: no target in: {s}\n", .{next});
} }
} }
// 3. connect whether asked to and send a message
// TODO: currently only switching with other UNIX sockets ^^'.
// Should contact <protocol>d.
// 3. connect whether asked to and send a message
if (final_destination) |dest| { if (final_destination) |dest| {
print("Let's contact {s} (original service requested: {s})\n" print("Let's contact {s} (service requested: {s})\n"
, .{dest, service_to_contact}); , .{dest, service_to_contact});
var iterator3 = std.mem.split(u8, dest, "://"); var uri = URI.read(dest);
var protocol = iterator3.first();
print("Protocol: {s}\n" , .{protocol});
// 1. in case there is no URI // 1. in case there is no URI
if (std.mem.eql(u8, protocol, dest)) { if (std.mem.eql(u8, uri.protocol, dest)) {
var newfd = try ctx.connect_service (dest); var newfd = try ctx.connect_service (dest);
send_fd (some_event.origin, "ok", newfd); send_fd (some_event.origin, "ok", newfd);
try ctx.close_fd (newfd); try ctx.close_fd (newfd);
} }
else if (std.mem.eql(u8, protocol, "unix")) { else if (std.mem.eql(u8, uri.protocol, "unix")) {
var newfd = try ctx.connect_service (iterator3.next().?); var newfd = try ctx.connect_service (uri.address);
send_fd (some_event.origin, "ok", newfd); send_fd (some_event.origin, "ok", newfd);
try ctx.close_fd (newfd); try ctx.close_fd (newfd);
} }
// 2. else, contact <protocol>d or directly the dest in case there is none. // 2. else, contact <protocol>d or directly the dest in case there is none.
else { else {
print("should contact {s}d: TODO\n", .{protocol}); var servicefd = try ctx.connect_service (uri.protocol);
var servicefd = try ctx.connect_service (protocol);
defer ctx.close_fd (servicefd) catch {}; defer ctx.close_fd (servicefd) catch {};
// TODO: make a simple protocol between IPCd and <protocol>d // TODO: make a simple protocol between IPCd and <protocol>d
// NEED inform about the connection (success or fail) // NEED inform about the connection (success or fail)
@ -178,7 +174,7 @@ fn create_service() !void {
defer r.deinit(); defer r.deinit();
if (std.mem.eql(u8, r.payload, "ok")) { if (std.mem.eql(u8, r.payload, "ok")) {
// OK // OK
print("service has established the connection\n", .{}); // print("service has established the connection\n", .{});
send_fd (some_event.origin, "ok", servicefd); send_fd (some_event.origin, "ok", servicefd);
} }
else if (std.mem.eql(u8, r.payload, "ne")) { else if (std.mem.eql(u8, r.payload, "ne")) {

View File

@ -256,7 +256,7 @@ test "nuke 'em" {
} }
fn default_in (origin: i32, m: *Message) CBEventType { fn default_in (origin: i32, m: *Message) CBEventType {
print ("receiving a message originated from {}\n", .{origin}); // print ("receiving a message originated from {}\n", .{origin});
var buffer: [2000000]u8 = undefined; // TODO: FIXME?? var buffer: [2000000]u8 = undefined; // TODO: FIXME??
var packet_size: usize = undefined; var packet_size: usize = undefined;
@ -275,8 +275,8 @@ fn default_in (origin: i32, m: *Message) CBEventType {
return CBEventType.NO_ERROR; return CBEventType.NO_ERROR;
} }
fn default_out (origin: i32, m: *const Message) CBEventType { fn default_out (_: i32, m: *const Message) CBEventType {
print ("sending a message originated from {}\n", .{origin}); // print ("sending a message originated from {}\n", .{origin});
// Message contains the fd, no need to search for // Message contains the fd, no need to search for
// the right structure to copy, let's just recreate // the right structure to copy, let's just recreate
// a Stream from the fd. // a Stream from the fd.