diff options
author | 2022-01-25 00:17:14 -0800 | |
---|---|---|
committer | 2022-01-25 00:17:14 -0800 | |
commit | 333bccee5dd0d4f63f3f83b00d62c32ba5806f5d (patch) | |
tree | f7e5ab04f5d7cd315f668375aaafd30a116ba669 /src | |
parent | 25c35e59b4054dfef5d971d0690cc085d6956647 (diff) | |
download | bun-333bccee5dd0d4f63f3f83b00d62c32ba5806f5d.tar.gz bun-333bccee5dd0d4f63f3f83b00d62c32ba5806f5d.tar.zst bun-333bccee5dd0d4f63f3f83b00d62c32ba5806f5d.zip |
On successful connect, switch to non-blocking sockets until we're about to close
Diffstat (limited to 'src')
-rw-r--r-- | src/io/io_linux.zig | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/io/io_linux.zig b/src/io/io_linux.zig index ed2c3936b..8e0a64f7d 100644 --- a/src/io/io_linux.zig +++ b/src/io/io_linux.zig @@ -142,7 +142,7 @@ const os = struct { pub const EHWPOISON = 133; }; -pub const pretend_older_kernel = false; +pub const pretend_older_kernel = true; const Features = struct { connect_poll: bool = pretend_older_kernel, close_poll: bool = pretend_older_kernel, @@ -796,7 +796,16 @@ pub const Completion = struct { os.EPROTOTYPE => error.ProtocolNotSupported, os.ETIMEDOUT => error.ConnectionTimedOut, else => |errno| asError(errno), - } else assert(completion.result == 0); + } else { + // go back to blocking mode + var opts = linux.fcntl(op.socket, os.F.GETFL, 0); + if ((opts & os.O.NONBLOCK) != 0) { + opts &= ~(@as(u32, os.O.NONBLOCK)); + _ = linux.fcntl(op.socket, os.F.SETFL, opts); + } + + assert(completion.result == 0); + }; completion.callback(completion.context, completion, &result); }, .connect => { @@ -1080,6 +1089,13 @@ pub fn close( }; if (features.close_poll) { + // go to non-blocking mode + var opts = linux.fcntl(fd, os.F.GETFL, 0); + if ((opts & os.O.NONBLOCK) == 0) { + opts |= os.O.NONBLOCK; + _ = linux.fcntl(fd, os.F.SETFL, opts); + } + const rc = linux.close(fd); switch (linux.getErrno(rc)) { .AGAIN, .INPROGRESS, .INTR => {}, |