diff options
author | 2022-11-24 18:57:58 -0800 | |
---|---|---|
committer | 2022-11-24 18:57:58 -0800 | |
commit | 5a95fae533cea2be73d78518ed52cd9ebf304a59 (patch) | |
tree | d98fc72766752bbc762f792ba3de1a53ae980eb1 /src/global.zig | |
parent | 47f0e14477721a0c1c9f5458208c632fc2e4a370 (diff) | |
download | bun-5a95fae533cea2be73d78518ed52cd9ebf304a59.tar.gz bun-5a95fae533cea2be73d78518ed52cd9ebf304a59.tar.zst bun-5a95fae533cea2be73d78518ed52cd9ebf304a59.zip |
Improve SIGPIPE handling
Diffstat (limited to '')
-rw-r--r-- | src/global.zig | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/global.zig b/src/global.zig index 5312b0c05..1dccb15e7 100644 --- a/src/global.zig +++ b/src/global.zig @@ -357,18 +357,25 @@ pub fn isReadable(fd: std.os.fd_t) bool { // return result; } -pub fn isWritable(fd: std.os.fd_t) bool { +pub const WritableFlag = enum { writable, not_writable, hup }; +pub fn isWritable(fd: std.os.fd_t) WritableFlag { var polls = &[_]std.os.pollfd{ .{ .fd = fd, - .events = std.os.POLL.OUT | std.os.POLL.ERR, + .events = std.os.POLL.OUT, .revents = 0, }, }; const result = (std.os.poll(polls, 0) catch 0) != 0; - global_scope_log("isWritable: {d}", .{result}); - return result; + global_scope_log("isWritable: {d} ({d})", .{ result, polls[0].revents }); + if (result and polls[0].revents & std.os.POLL.HUP != 0) { + return WritableFlag.hup; + } else if (result) { + return WritableFlag.writable; + } else { + return WritableFlag.not_writable; + } } pub inline fn unreachablePanic(comptime fmts: []const u8, args: anytype) noreturn { |