Repository navigation
Fix all Codex adversarial review findings #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cdb28f9
00f162c
5499895
df598dd
b704e57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,15 +133,20 @@ pub fn acceptClient(listen_fd: std.posix.fd_t) !std.posix.fd_t { | |
|
|
||
| /// Read a complete message from client fd into buf. | ||
| /// Returns msg_type + payload slice, or null if EOF/disconnect. | ||
| /// Returns error.WouldBlock if no data available yet (EAGAIN). | ||
| /// Returns error.WouldBlock if no data available yet (EAGAIN) AND no bytes have been read. | ||
| /// If partial data was consumed and WouldBlock occurs, returns null (disconnect) to avoid | ||
| /// busy-looping on the single-threaded event loop. | ||
| pub fn readMessage(fd: std.posix.fd_t, buf: []u8) error{WouldBlock}!?struct { msg_type: u32, payload: []const u8 } { | ||
| if (buf.len < HEADER_SIZE) return null; | ||
|
|
||
| // Read header | ||
| var total_read: usize = 0; | ||
| while (total_read < HEADER_SIZE) { | ||
| const n = std.posix.read(fd, buf[total_read..]) catch |err| { | ||
| if (err == error.WouldBlock) return error.WouldBlock; | ||
| if (err == error.WouldBlock) { | ||
| if (total_read == 0) return error.WouldBlock; | ||
| return null; // Partial header + WouldBlock: drop client to avoid busy-loop | ||
| } | ||
|
Comment on lines
+146
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| return null; | ||
| }; | ||
| if (n == 0) return null; // EOF | ||
|
|
@@ -155,10 +160,10 @@ pub fn readMessage(fd: std.posix.fd_t, buf: []u8) error{WouldBlock}!?struct { ms | |
| const total_needed = HEADER_SIZE + payload_len; | ||
| if (buf.len < total_needed) return null; | ||
|
|
||
| // Read payload | ||
| // Read payload — once header is read, we must complete the message | ||
| while (total_read < total_needed) { | ||
| const n = std.posix.read(fd, buf[total_read..total_needed]) catch |err| { | ||
| if (err == error.WouldBlock) return error.WouldBlock; | ||
| if (err == error.WouldBlock) return null; // Partial payload: drop client to avoid busy-loop | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This branch treats Useful? React with 👍 / 👎. |
||
| return null; | ||
| }; | ||
| if (n == 0) return null; | ||
|
|
@@ -203,10 +208,10 @@ pub fn sendRequest(allocator: std.mem.Allocator, sock_path: []const u8, msg_type | |
| const fd = connectToServer(sock_path) catch return null; | ||
| defer std.posix.close(fd); | ||
|
|
||
| // Send | ||
| // Send (use writeAll to handle partial writes correctly) | ||
| var send_buf: [4096 + HEADER_SIZE]u8 = undefined; | ||
| const msg = encode(msg_type, payload, &send_buf); | ||
| _ = std.posix.write(fd, msg) catch return null; | ||
| writeAll(fd, msg) catch return null; | ||
|
|
||
| // Read response | ||
| var recv_buf: [65536]u8 = undefined; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.