Skip to content

Commit

Permalink
fix(aio): connect should return void
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Mar 9, 2025
1 parent 0c2bb10 commit ef40de9
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 52 deletions.
28 changes: 6 additions & 22 deletions src/aio/apis/epoll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -369,31 +369,15 @@ pub const AsyncEpoll = struct {

break :blk .{ .accept = result };
},
.connect => |inner| {
.connect => |_| {
assert(event.events & std.os.linux.EPOLL.OUT != 0);

const result: ConnectResult = result: {
std.posix.connect(
inner.socket,
&inner.addr.any,
inner.addr.getOsSockLen(),
) catch |e| {
const err = switch (e) {
std.posix.ConnectError.WouldBlock => {
job_complete = false;
continue;
},
else => ConnectError.Unexpected,
};

break :result .{ .err = err };
};

break :result .{ .actual = .{
.handle = inner.socket,
.addr = inner.addr,
.kind = inner.kind,
} };
if (event.events & std.os.linux.EPOLL.ERR != 0) {
break :result .{ .err = ConnectError.Unexpected };
} else {
break :result .actual;
}
};

break :blk .{ .connect = result };
Expand Down
8 changes: 2 additions & 6 deletions src/aio/apis/io_uring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,8 @@ pub const AsyncIoUring = struct {

break :blk .{ .accept = result };
},
.connect => |inner| {
if (cqe.res >= 0) break :blk .{
.connect = .{
.actual = .{ .handle = inner.socket, .addr = inner.addr, .kind = inner.kind },
},
};
.connect => |_| {
if (cqe.res >= 0) break :blk .{ .connect = .actual };

const result: ConnectResult = result: {
const e: LinuxError = @enumFromInt(-cqe.res);
Expand Down
10 changes: 2 additions & 8 deletions src/aio/apis/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub const AsyncKqueue = struct {

break :blk .{ .accept = result };
},
.connect => |inner| {
.connect => |_| {
assert(event.filter == std.posix.system.EVFILT_WRITE);

const result: ConnectResult = result: {
Expand All @@ -412,13 +412,7 @@ pub const AsyncKqueue = struct {
else => ConnectError.Unexpected,
};
break :result .{ .err = err };
} else break :result .{
.actual = .{
.handle = inner.socket,
.addr = inner.addr,
.kind = inner.kind,
},
};
} else break :result .actual;
};

break :blk .{ .connect = result };
Expand Down
12 changes: 2 additions & 10 deletions src/aio/apis/poll.zig
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,13 @@ pub const AsyncPoll = struct {
},
};
},
.connect => |inner| {
.connect => |_| {
assert(pollfd.revents & std.posix.POLL.OUT != 0);

if (pollfd.revents & std.posix.POLL.ERR != 0) {
break :result .{ .connect = .{ .err = ConnectError.Unexpected } };
} else {
break :result .{
.connect = .{
.actual = .{
.handle = inner.socket,
.addr = inner.addr,
.kind = inner.kind,
},
},
};
break :result .{ .connect = .actual };
}
},
.recv => |inner| {
Expand Down
2 changes: 1 addition & 1 deletion src/aio/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ pub const DeleteError = error{

pub const AcceptResult = Resulted(Socket, AcceptError);

pub const ConnectResult = Resulted(Socket, ConnectError);
pub const ConnectResult = Resulted(void, ConnectError);
pub const RecvResult = Resulted(usize, RecvError);

pub const SendResult = Resulted(usize, SendError);
Expand Down
6 changes: 2 additions & 4 deletions src/net/socket.zig
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub const Socket = struct {
}
}

pub fn connect(self: Socket, rt: *Runtime) !Socket {
pub fn connect(self: Socket, rt: *Runtime) !void {
if (rt.aio.features.has_capability(.connect)) {
try rt.scheduler.io_await(.{
.connect = .{
Expand All @@ -187,7 +187,7 @@ pub const Socket = struct {

const index = rt.current_task.?;
const task = rt.scheduler.tasks.get(index);
return try task.result.connect.unwrap();
try task.result.connect.unwrap();
} else {
while (true) {
break std.posix.connect(
Expand All @@ -202,8 +202,6 @@ pub const Socket = struct {
else => ConnectError.Unexpected,
};
}

return self;
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tcp_chain.zig
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub const TcpClientChain = struct {
const current_step = chain.steps[chain.index];
log.debug("client chain step: {s}", .{@tagName(current_step)});
switch (current_step) {
.connect => _ = try socket.connect(rt),
.connect => try socket.connect(rt),
.recv => {
const length = socket.recv(rt, chain.buffer) catch |e| switch (e) {
error.Closed => break :chain,
Expand Down

0 comments on commit ef40de9

Please sign in to comment.