2008-01-05 19:37:13 -05:00
|
|
|
USING: continuations destructors io.buffers io.nonblocking
|
|
|
|
io.windows io.windows.nt.backend kernel libc math threads
|
|
|
|
windows windows.kernel32 ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.windows.nt.files
|
|
|
|
|
2007-11-23 20:17:40 -05:00
|
|
|
M: windows-nt-io CreateFile-flags ( DWORD -- DWORD )
|
|
|
|
FILE_FLAG_OVERLAPPED bitor ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: windows-nt-io FileArgs-overlapped ( port -- overlapped )
|
|
|
|
make-overlapped ;
|
|
|
|
|
|
|
|
: update-file-ptr ( n port -- )
|
|
|
|
port-handle
|
|
|
|
dup win32-file-ptr [
|
|
|
|
rot + swap set-win32-file-ptr
|
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] if* ;
|
|
|
|
|
2008-01-28 00:59:36 -05:00
|
|
|
: finish-flush ( overlapped port -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
dup pending-error
|
2008-01-28 00:59:36 -05:00
|
|
|
tuck get-overlapped-result
|
2007-11-07 14:01:45 -05:00
|
|
|
dup pick update-file-ptr
|
|
|
|
swap buffer-consume ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: (flush-output) ( port -- )
|
|
|
|
dup make-FileArgs
|
2007-11-07 14:01:45 -05:00
|
|
|
tuck setup-write WriteFile
|
|
|
|
dupd overlapped-error? [
|
2008-01-28 00:59:36 -05:00
|
|
|
>r FileArgs-lpOverlapped r>
|
|
|
|
[ save-callback ] 2keep
|
2007-11-07 14:01:45 -05:00
|
|
|
[ finish-flush ] keep
|
|
|
|
dup buffer-empty? [ drop ] [ (flush-output) ] if
|
2007-09-20 18:09:08 -04:00
|
|
|
] [
|
|
|
|
2drop
|
|
|
|
] if ;
|
|
|
|
|
2007-11-09 03:01:45 -05:00
|
|
|
: flush-output ( port -- )
|
2008-01-31 13:27:37 -05:00
|
|
|
[ [ (flush-output) ] with-port-timeout ] with-destructors ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2007-11-09 03:01:45 -05:00
|
|
|
M: port port-flush
|
|
|
|
dup buffer-empty? [ dup flush-output ] unless drop ;
|
|
|
|
|
2008-01-28 00:59:36 -05:00
|
|
|
: finish-read ( overlapped port -- )
|
2007-09-20 18:09:08 -04:00
|
|
|
dup pending-error
|
2008-01-28 00:59:36 -05:00
|
|
|
tuck get-overlapped-result dup zero? [
|
2007-09-20 18:09:08 -04:00
|
|
|
drop t swap set-port-eof?
|
|
|
|
] [
|
2007-11-07 14:01:45 -05:00
|
|
|
dup pick n>buffer
|
2007-09-20 18:09:08 -04:00
|
|
|
swap update-file-ptr
|
|
|
|
] if ;
|
|
|
|
|
|
|
|
: ((wait-to-read)) ( port -- )
|
|
|
|
dup make-FileArgs
|
2007-11-07 14:01:45 -05:00
|
|
|
tuck setup-read ReadFile
|
|
|
|
dupd overlapped-error? [
|
2008-01-28 00:59:36 -05:00
|
|
|
>r FileArgs-lpOverlapped r>
|
|
|
|
[ save-callback ] 2keep
|
2007-09-20 18:09:08 -04:00
|
|
|
finish-read
|
2008-01-31 13:27:37 -05:00
|
|
|
] [ 2drop ] if ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
M: input-port (wait-to-read) ( port -- )
|
2008-01-31 13:27:37 -05:00
|
|
|
[ [ ((wait-to-read)) ] with-port-timeout ] with-destructors ;
|