Skip to content

Commit

Permalink
continued reworking of sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Sep 25, 2024
1 parent 793c1a6 commit ea9f955
Show file tree
Hide file tree
Showing 6 changed files with 260 additions and 196 deletions.
18 changes: 11 additions & 7 deletions src/async/busy_loop.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const std = @import("std");
const builtin = @import("builtin");
const Completion = @import("completion.zig").Completion;

const Async = @import("lib.zig").Async;
Expand Down Expand Up @@ -67,19 +68,22 @@ pub const AsyncBusyLoop = struct {
.accept => |inner| {
const com_ptr = &self.completions[reaped];

const res: i32 = blk: {
const res: std.posix.socket_t = blk: {
const ad = std.posix.accept(inner.socket, null, null, 0) catch |e| {
if (e == error.WouldBlock) {
continue;
} else {
break :blk -1;
switch (comptime builtin.target.os.tag) {
.windows => break :blk std.os.windows.ws2_32.INVALID_SOCKET,
else => break :blk -1,
}
}
};

break :blk @intCast(ad);
break :blk ad;
};

com_ptr.result = @intCast(res);
com_ptr.result = .{ .socket = res };
com_ptr.context = inner.context;
_ = list.swapRemove(i);
i -|= 1;
Expand All @@ -100,7 +104,7 @@ pub const AsyncBusyLoop = struct {
break :blk @intCast(rd);
};

com_ptr.result = @intCast(len);
com_ptr.result = .{ .value = @intCast(len) };
com_ptr.context = inner.context;
_ = list.swapRemove(i);
i -|= 1;
Expand All @@ -121,7 +125,7 @@ pub const AsyncBusyLoop = struct {
break :blk @intCast(sd);
};

com_ptr.result = @intCast(len);
com_ptr.result = .{ .value = @intCast(len) };
com_ptr.context = inner.context;
_ = list.swapRemove(i);
i -|= 1;
Expand All @@ -131,7 +135,7 @@ pub const AsyncBusyLoop = struct {
.close => |inner| {
const com_ptr = &self.completions[reaped];
std.posix.close(inner.socket);
com_ptr.result = 0;
com_ptr.result = .{ .value = 0 };
com_ptr.context = inner.context;
_ = list.swapRemove(i);
i -|= 1;
Expand Down
12 changes: 6 additions & 6 deletions src/async/completion.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const std = @import("std");

const CompletionResult = union {
socket: std.posix.socket_t,
result: i32,
};

pub const Completion = struct {
pub const Result = union {
socket: std.posix.socket_t,
value: i32,
};

context: *anyopaque,
result: i32,
result: Result,
};
Loading

0 comments on commit ea9f955

Please sign in to comment.