diff options
Diffstat (limited to 'core/os/os2/pipe_posix.odin')
| -rw-r--r-- | core/os/os2/pipe_posix.odin | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/core/os/os2/pipe_posix.odin b/core/os/os2/pipe_posix.odin index 487e32aea..463f29f01 100644 --- a/core/os/os2/pipe_posix.odin +++ b/core/os/os2/pipe_posix.odin @@ -44,3 +44,28 @@ _pipe :: proc() -> (r, w: ^File, err: Error) { return } +@(require_results) +_pipe_has_data :: proc(r: ^File) -> (ok: bool, err: Error) { + if r == nil || r.impl == nil { + return false, nil + } + fd := posix.FD((^File_Impl)(r.impl).fd) + poll_fds := []posix.pollfd { + posix.pollfd { + fd = fd, + events = {.IN, .HUP}, + }, + } + n := posix.poll(raw_data(poll_fds), u32(len(poll_fds)), 0) + if n != 1 { + return false, _get_platform_error() + } + pipe_events := poll_fds[0].revents + if pipe_events >= {.IN} { + return true, nil + } + if pipe_events >= {.HUP} { + return false, .Broken_Pipe + } + return false, nil +}
\ No newline at end of file |