mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
[os2]: Implement pipe_has_data procedure
This commit is contained in:
@@ -15,3 +15,29 @@ _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 := linux.Fd((^File_Impl)(r.impl).fd)
|
||||
poll_fds := []linux.Poll_Fd {
|
||||
linux.Poll_Fd {
|
||||
fd = fd,
|
||||
events = {.IN, .HUP},
|
||||
},
|
||||
}
|
||||
n, errno := linux.poll(poll_fds, 0)
|
||||
if n != 1 || errno != nil {
|
||||
return false, _get_platform_error(errno)
|
||||
}
|
||||
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