Changes
3 changed files (+16/-16)
-
-
@@ -83,7 +83,7 @@ return null;}; const info = RegistryService.info(allocator, conn) catch |err| { std.debug.print("Info request failed: {s}\n", .{@errorName(err)}); std.log.err("Failed to get extension registry status: {s}", .{@errorName(err)}); return null; }; defer info.deinit();
-
@@ -93,7 +93,7 @@ .token = if (token) |tok| std.mem.span(tok) else null,}; const register = RegistryService.register(AppExtension, allocator, conn, extension) catch |err| { std.debug.print("Register request failed: {s}\n", .{@errorName(err)}); std.log.err("Failed to register extension: {s}", .{@errorName(err)}); return null; }; defer register.deinit();
-
-
-
@@ -107,8 +107,8 @@ self.thread = try std.Thread.spawn(.{}, readLoop, .{ self, on_request });} pub fn deinit(self: *Connection) void { self.ws.close(.{}) catch { std.debug.print("Failed to close WebSocket connection\n", .{}); self.ws.close(.{}) catch |err| { std.log.warn("Failed to close WebSocket connection, proceeding: {s}", .{@errorName(err)}); }; if (self.thread) |thread| { // Wait for read thread to terminate.
-
@@ -163,7 +163,7 @@// TODO: Better logging fn readLoop(conn: *Connection, on_request: RequestHandler) void { conn.ws.readTimeout(1_000) catch |err| { std.debug.print("Unable to set read timeout: {s}\n", .{@errorName(err)}); std.log.err("Unable to set WebSocket read timeout: {s}", .{@errorName(err)}); return; };
-
@@ -175,13 +175,13 @@ switch (msg.type) {// NOTE: roon-node-api does not check whether message is binaryType. .text, .binary => { const meta, const header_ctx = moo.Metadata.parse(msg.data) catch |err| { std.debug.print("Received non-MOO message: {s}\n", .{@errorName(err)}); std.log.warn("Failed to parse MOO metadata: {s}", .{@errorName(err)}); continue; }; // We just want to know Request-Id header. const header, _ = moo.NoBodyHeaders.parse(msg.data, header_ctx) catch |err| { std.debug.print("Received non-MOO message: {s}\n", .{@errorName(err)}); std.log.warn("Failed to parse MOO headers: {s}", .{@errorName(err)}); continue; };
-
@@ -191,8 +191,8 @@ defer conn.responses_mutex.unlock();if (conn.responses.get(header.request_id)) |store| { if (store.wrote.isSet()) { std.debug.print( "Received duplicated message: Request-Id={d}\n", std.log.warn( "Received more than one message having same Request-Id({d})", .{header.request_id}, ); continue;
-
@@ -200,8 +200,8 @@ }defer store.wrote.set(); const bytes = conn.allocator.dupe(u8, msg.data) catch { std.debug.print("Out of memory during cloning WebSocket message", .{}); const bytes = conn.allocator.dupe(u8, msg.data) catch |err| { std.log.err("Unable to release incoming WS message: {s}", .{@errorName(err)}); return; };
-
@@ -214,22 +214,22 @@ var buffer = std.ArrayList(u8).init(conn.allocator);defer buffer.deinit(); const wrote = on_request(buffer.writer(), meta, header_ctx, msg.data) catch |err| { std.debug.print("Request handling error: {s}\n", .{@errorName(err)}); std.log.warn("Service server handler returned an error: {s}", .{@errorName(err)}); continue; }; if (!wrote) { std.debug.print("Incoming message not processed: service={s}\n", .{meta.service}); std.log.info("Unhandled incoming request: service={s}\n", .{meta.service}); continue; } const bytes = buffer.toOwnedSlice() catch |err| { std.debug.print("Unable to prepare response bytes: {s}\n", .{@errorName(err)}); std.log.warn("Unable to prepare response bytes: {s}\n", .{@errorName(err)}); continue; }; conn.ws.writeBin(bytes) catch |err| { std.debug.print("Failed to write response message: {s}\n", .{@errorName(err)}); std.log.warn("Failed to write response message: {s}\n", .{@errorName(err)}); continue; }; },
-
-
-
@@ -86,7 +86,7 @@ errdefer conn.allocator.free(message);const meta_res, const header_ctx = try moo.Metadata.parse(message); if (!std.mem.eql(u8, meta_res.service, "Registered")) { std.debug.print("Expected \"Registered\" for /register endpoint, got \"{s}\"\n", .{meta_res.service}); std.log.err("Expected \"Registered\" for /register endpoint, got \"{s}\"\n", .{meta_res.service}); return RegisterError.NonSuccessResponse; }
-