aboutsummaryrefslogtreecommitdiff
path: root/src/io/io_linux.zig
diff options
context:
space:
mode:
authorGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-03-16 08:01:56 -0700
committerGravatar Jarred SUmner <jarred@jarredsumner.com> 2022-03-16 08:02:15 -0700
commit6bcaa337511928521a2ec82e4703f331194e79ff (patch)
treea95df2775e3705467aa2b8c1c36d7a921949a85b /src/io/io_linux.zig
parent8b73afad95c3abd2e7e1038beb84198f266abd95 (diff)
downloadbun-6bcaa337511928521a2ec82e4703f331194e79ff.tar.gz
bun-6bcaa337511928521a2ec82e4703f331194e79ff.tar.zst
bun-6bcaa337511928521a2ec82e4703f331194e79ff.zip
Fix setTimeout on Linux
Diffstat (limited to 'src/io/io_linux.zig')
-rw-r--r--src/io/io_linux.zig17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig
index 4e4d9137f..f4ea7fd46 100644
--- a/src/io/io_linux.zig
+++ b/src/io/io_linux.zig
@@ -433,7 +433,7 @@ pub fn asError(err: anytype) Errno {
};
}
-const timespec = std.os.system.timespec;
+const timespec = linux.timespec;
const linux = os.linux;
const IO_Uring = linux.IO_Uring;
const io_uring_cqe = linux.io_uring_cqe;
@@ -444,6 +444,8 @@ const IO = @This();
ring: IO_Uring,
+pending_timeouts: u32 = 0,
+
/// Operations not yet submitted to the kernel and waiting on available space in the
/// submission queue.
unqueued: FIFO(Completion) = .{},
@@ -454,7 +456,9 @@ completed: FIFO(Completion) = .{},
next_tick: FIFO(Completion) = .{},
pub fn hasNoWork(this: *IO) bool {
- return this.completed.peek() == null and this.unqueued.peek() == null and this.next_tick.peek() == null;
+ return this.completed.peek() == null and this.unqueued.peek() == null and
+ this.next_tick.peek() == null and
+ this.pending_timeouts == 0;
}
pub fn init(entries_: u12, flags: u32) !IO {
@@ -712,8 +716,9 @@ pub const Completion = struct {
.send => |op| {
linux.io_uring_prep_send(sqe, op.socket, op.buffer, os.MSG.NOSIGNAL);
},
- .timeout => |*op| {
- linux.io_uring_prep_timeout(sqe, &op.timespec, 0, 0);
+ .timeout => {
+ var op = &completion.operation.timeout;
+ linux.io_uring_prep_timeout(sqe, &op.timespec, 1, 0);
},
.write => |op| {
linux.io_uring_prep_write(
@@ -940,7 +945,7 @@ const Operation = union(enum) {
buffer: []const u8,
},
timeout: struct {
- timespec: os.timespec,
+ timespec: linux.timespec,
},
write: struct {
fd: os.fd_t,
@@ -1395,11 +1400,13 @@ pub fn timeout(
completion: *Completion,
nanoseconds: u63,
) void {
+ self.pending_timeouts +|= 1;
completion.* = .{
.io = self,
.context = context,
.callback = struct {
fn wrapper(ctx: ?*anyopaque, comp: *Completion, res: *const anyopaque) void {
+ comp.io.pending_timeouts -|= 1;
callback(
@intToPtr(Context, @ptrToInt(ctx)),
comp,