aboutsummaryrefslogtreecommitdiff
path: root/src/global.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/global.zig41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/global.zig b/src/global.zig
index 1dccb15e7..635e759ce 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -341,24 +341,27 @@ pub fn ensureNonBlocking(fd: anytype) void {
}
const global_scope_log = Output.scoped(.bun, false);
-pub fn isReadable(fd: std.os.fd_t) bool {
- _ = fd;
- return false;
- // var polls = &[_]std.os.pollfd{
- // .{
- // .fd = fd,
- // .events = std.os.POLL.IN | std.os.POLL.ERR,
- // .revents = 0,
- // },
- // };
-
- // const result = (std.os.poll(polls, 0) catch 0) != 0;
- // global_scope_log("isReadable: {d}", .{result});
- // return result;
+pub fn isReadable(fd: std.os.fd_t) PollFlag {
+ var polls = &[_]std.os.pollfd{
+ .{
+ .fd = fd,
+ .events = std.os.POLL.IN | std.os.POLL.ERR,
+ .revents = 0,
+ },
+ };
+
+ const result = (std.os.poll(polls, 0) catch 0) != 0;
+ global_scope_log("isReadable: {d} ({d})", .{ result, polls[0].revents });
+ return if (result and polls[0].revents & std.os.POLL.HUP != 0)
+ PollFlag.hup
+ else if (result)
+ PollFlag.ready
+ else
+ PollFlag.not_ready;
}
-pub const WritableFlag = enum { writable, not_writable, hup };
-pub fn isWritable(fd: std.os.fd_t) WritableFlag {
+pub const PollFlag = enum { ready, not_ready, hup };
+pub fn isWritable(fd: std.os.fd_t) PollFlag {
var polls = &[_]std.os.pollfd{
.{
.fd = fd,
@@ -370,11 +373,11 @@ pub fn isWritable(fd: std.os.fd_t) WritableFlag {
const result = (std.os.poll(polls, 0) catch 0) != 0;
global_scope_log("isWritable: {d} ({d})", .{ result, polls[0].revents });
if (result and polls[0].revents & std.os.POLL.HUP != 0) {
- return WritableFlag.hup;
+ return PollFlag.hup;
} else if (result) {
- return WritableFlag.writable;
+ return PollFlag.ready;
} else {
- return WritableFlag.not_writable;
+ return PollFlag.not_ready;
}
}