Skip to content

Commit a130463

Browse files
authored
os: implement Process.is_pending() on windows (fix #23990) (#23993)
1 parent 76ae040 commit a130463

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎vlib/os/process.c.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn (mut p Process) _write_to(pkind ChildProcessPipeKind, s string) {
248248
// _is_pending should be called only from is_pending()
249249
fn (mut p Process) _is_pending(pkind ChildProcessPipeKind) bool {
250250
$if windows {
251-
// TODO
251+
return p.win_is_pending(int(pkind))
252252
} $else {
253253
return fd_is_pending(p.stdio_fd[pkind])
254254
}

‎vlib/os/process_nix.c.v‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ fn (mut p Process) win_read_string(_idx int, _maxbytes int) (string, int) {
154154
return '', 0
155155
}
156156

157+
fn (mut p Process) win_is_pending(idx int) bool {
158+
return false
159+
}
160+
157161
fn (mut p Process) win_slurp(_idx int) string {
158162
return ''
159163
}

‎vlib/os/process_windows.c.v‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ fn (mut p Process) win_spawn_process() int {
8888
sa.n_length = sizeof(C.SECURITY_ATTRIBUTES)
8989
sa.b_inherit_handle = true
9090
create_pipe_ok1 := C.CreatePipe(voidptr(&wdata.child_stdout_read), voidptr(&wdata.child_stdout_write),
91-
voidptr(&sa), 0)
91+
voidptr(&sa), 65536)
9292
failed_cfn_report_error(create_pipe_ok1, 'CreatePipe stdout')
9393
set_handle_info_ok1 := C.SetHandleInformation(wdata.child_stdout_read, C.HANDLE_FLAG_INHERIT,
9494
0)
9595
failed_cfn_report_error(set_handle_info_ok1, 'SetHandleInformation')
9696
create_pipe_ok2 := C.CreatePipe(voidptr(&wdata.child_stderr_read), voidptr(&wdata.child_stderr_write),
97-
voidptr(&sa), 0)
97+
voidptr(&sa), 65536)
9898
failed_cfn_report_error(create_pipe_ok2, 'CreatePipe stderr')
9999
set_handle_info_ok2 := C.SetHandleInformation(wdata.child_stderr_read, C.HANDLE_FLAG_INHERIT,
100100
0)
@@ -233,6 +233,28 @@ fn (mut p Process) win_read_string(idx int, _maxbytes int) (string, int) {
233233
return buf[..bytes_read].bytestr(), bytes_read
234234
}
235235

236+
fn (mut p Process) win_is_pending(idx int) bool {
237+
mut wdata := unsafe { &WProcess(p.wdata) }
238+
if unsafe { wdata == 0 } {
239+
return false
240+
}
241+
mut rhandle := &u32(0)
242+
if idx == 1 {
243+
rhandle = wdata.child_stdout_read
244+
}
245+
if idx == 2 {
246+
rhandle = wdata.child_stderr_read
247+
}
248+
if rhandle == 0 {
249+
return false
250+
}
251+
mut bytes_avail := int(0)
252+
if C.PeekNamedPipe(rhandle, 0, 0, 0, &bytes_avail, 0) {
253+
return bytes_avail > 0
254+
}
255+
return false
256+
}
257+
236258
fn (mut p Process) win_slurp(idx int) string {
237259
mut wdata := unsafe { &WProcess(p.wdata) }
238260
if unsafe { wdata == 0 } {

0 commit comments

Comments
 (0)