Repository navigation
Cleanup net.zig - #226
Cleanup net.zig#226
Conversation
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughAdds Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/net.zig`:
- Around line 793-805: The function setBoolOption has a type mismatch: optname
is declared as u32 but both os.windows.setsockopt and std.posix.setsockopt
expect an i32; change the parameter signature in setBoolOption from optname: u32
to optname: i32 (in the fn setBoolOption declaration) and update any call sites
that pass a u32 constant to cast or use i32 values to match the new signature;
keep the rest of the implementation (value/memory handling and platform
branches) unchanged.
- Line 796: The Windows setsockopt call is passing optname as u32 which causes a
mismatch; cast optname to i32 when calling os.windows.setsockopt (or change the
optname parameter to i32) — use `@intCast`(i32, optname) at the call site where
const rc = os.windows.setsockopt(self.handle, level, optname,
std.mem.asBytes(&value).ptr, `@sizeOf`(c_int)); so the third argument is
explicitly an i32 and matches the Windows API expectation.
| fn setBoolOption(self: Socket, level: i32, optname: u32, enabled: bool) !void { | ||
| const value: c_int = if (enabled) 1 else 0; | ||
| const bytes = std.mem.asBytes(&value); | ||
| try std.posix.setsockopt(self.handle, level, optname, bytes); | ||
| } | ||
|
|
||
| /// Helper function to set a boolean socket option (Windows) | ||
| fn setBoolOptionWindows(self: Socket, level: i32, optname: i32, enabled: bool) !void { | ||
| const value: c_int = if (enabled) 1 else 0; | ||
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); | ||
| if (rc == os.windows.SOCKET_ERROR) { | ||
| return error.Unexpected; | ||
| if (builtin.os.tag == .windows) { | ||
| const value: c_int = if (enabled) 1 else 0; | ||
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); | ||
| if (rc == os.windows.SOCKET_ERROR) { | ||
| return error.Unexpected; | ||
| } | ||
| } else { | ||
| const value: c_int = if (enabled) 1 else 0; | ||
| const bytes = std.mem.asBytes(&value); | ||
| try std.posix.setsockopt(self.handle, level, optname, bytes); | ||
| } | ||
| } |
There was a problem hiding this comment.
Type mismatch causes build failure.
Pipeline error is clear: optname is declared u32 but os.windows.setsockopt expects i32. The POSIX std.posix.setsockopt also expects i32 for the option name parameter.
Change the parameter type to i32:
🐛 Proposed fix
- fn setBoolOption(self: Socket, level: i32, optname: u32, enabled: bool) !void {
+ fn setBoolOption(self: Socket, level: i32, optname: i32, enabled: bool) !void {📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| fn setBoolOption(self: Socket, level: i32, optname: u32, enabled: bool) !void { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const bytes = std.mem.asBytes(&value); | |
| try std.posix.setsockopt(self.handle, level, optname, bytes); | |
| } | |
| /// Helper function to set a boolean socket option (Windows) | |
| fn setBoolOptionWindows(self: Socket, level: i32, optname: i32, enabled: bool) !void { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); | |
| if (rc == os.windows.SOCKET_ERROR) { | |
| return error.Unexpected; | |
| if (builtin.os.tag == .windows) { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); | |
| if (rc == os.windows.SOCKET_ERROR) { | |
| return error.Unexpected; | |
| } | |
| } else { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const bytes = std.mem.asBytes(&value); | |
| try std.posix.setsockopt(self.handle, level, optname, bytes); | |
| } | |
| } | |
| fn setBoolOption(self: Socket, level: i32, optname: i32, enabled: bool) !void { | |
| if (builtin.os.tag == .windows) { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, `@sizeOf`(c_int)); | |
| if (rc == os.windows.SOCKET_ERROR) { | |
| return error.Unexpected; | |
| } | |
| } else { | |
| const value: c_int = if (enabled) 1 else 0; | |
| const bytes = std.mem.asBytes(&value); | |
| try std.posix.setsockopt(self.handle, level, optname, bytes); | |
| } | |
| } |
🧰 Tools
🪛 GitHub Actions: Test coro
[error] 796-796: Command failed: zig build test -Dtest-filter=coro. -Doptimize=ReleaseSafe --summary all | Type mismatch: expected type 'i32', found 'u32' in setsockopt call (src/net.zig:796). The function optname is declared as i32 in os/windows.zig:696. Consider casting or changing the type to resolve the mismatch.
🤖 Prompt for AI Agents
In `@src/net.zig` around lines 793 - 805, The function setBoolOption has a type
mismatch: optname is declared as u32 but both os.windows.setsockopt and
std.posix.setsockopt expect an i32; change the parameter signature in
setBoolOption from optname: u32 to optname: i32 (in the fn setBoolOption
declaration) and update any call sites that pass a u32 constant to cast or use
i32 values to match the new signature; keep the rest of the implementation
(value/memory handling and platform branches) unchanged.
| return error.Unexpected; | ||
| if (builtin.os.tag == .windows) { | ||
| const value: c_int = if (enabled) 1 else 0; | ||
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); |
There was a problem hiding this comment.
Cast optname to i32 for Windows setsockopt.
Looking at both call sites: keeping the parameter as u32 and casting specifically for Windows is probably cleaner since the POSIX constants are typically u32.
Alternative fix if you'd rather not change the signature:
🔧 Alternative fix - cast at call site
- const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, `@sizeOf`(c_int));
+ const rc = os.windows.setsockopt(self.handle, level, `@intCast`(optname), std.mem.asBytes(&value).ptr, `@sizeOf`(c_int));Either approach works. The @intCast is safe here since socket option constants are small positive values well within i32 range.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const rc = os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr, @sizeOf(c_int)); | |
| const rc = os.windows.setsockopt(self.handle, level, `@intCast`(optname), std.mem.asBytes(&value).ptr, `@sizeOf`(c_int)); |
🧰 Tools
🪛 GitHub Actions: Test coro
[error] 796-796: Command failed: zig build test -Dtest-filter=coro. -Doptimize=ReleaseSafe --summary all | Type mismatch: expected type 'i32', found 'u32' in setsockopt call (src/net.zig:796). The function optname is declared as i32 in os/windows.zig:696. Consider casting or changing the type to resolve the mismatch.
🤖 Prompt for AI Agents
In `@src/net.zig` at line 796, The Windows setsockopt call is passing optname as
u32 which causes a mismatch; cast optname to i32 when calling
os.windows.setsockopt (or change the optname parameter to i32) — use
`@intCast`(i32, optname) at the call site where const rc =
os.windows.setsockopt(self.handle, level, optname, std.mem.asBytes(&value).ptr,
`@sizeOf`(c_int)); so the third argument is explicitly an i32 and matches the
Windows API expectation.
No description provided.