diff --git a/src/aio/apis/epoll.zig b/src/aio/apis/epoll.zig index 12067eb..c086333 100644 --- a/src/aio/apis/epoll.zig +++ b/src/aio/apis/epoll.zig @@ -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 }; diff --git a/src/aio/apis/io_uring.zig b/src/aio/apis/io_uring.zig index 8f29cfc..8404c83 100644 --- a/src/aio/apis/io_uring.zig +++ b/src/aio/apis/io_uring.zig @@ -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); diff --git a/src/aio/apis/kqueue.zig b/src/aio/apis/kqueue.zig index 0620db9..0a1d5a1 100644 --- a/src/aio/apis/kqueue.zig +++ b/src/aio/apis/kqueue.zig @@ -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: { @@ -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 }; diff --git a/src/aio/apis/poll.zig b/src/aio/apis/poll.zig index 745fcd7..837ff4c 100644 --- a/src/aio/apis/poll.zig +++ b/src/aio/apis/poll.zig @@ -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| { diff --git a/src/aio/completion.zig b/src/aio/completion.zig index 2186ab6..89ae21c 100644 --- a/src/aio/completion.zig +++ b/src/aio/completion.zig @@ -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); diff --git a/src/net/socket.zig b/src/net/socket.zig index 515c1b9..f15d701 100644 --- a/src/net/socket.zig +++ b/src/net/socket.zig @@ -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 = .{ @@ -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( @@ -202,8 +202,6 @@ pub const Socket = struct { else => ConnectError.Unexpected, }; } - - return self; } } diff --git a/test/e2e/tcp_chain.zig b/test/e2e/tcp_chain.zig index 29edd3f..5605448 100644 --- a/test/e2e/tcp_chain.zig +++ b/test/e2e/tcp_chain.zig @@ -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,