mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
[os2]: Implement pipe_has_data procedure
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user