io backend now uses OS singletons

db4
Doug Coleman 2008-04-02 20:09:56 -05:00
parent 72c06fc028
commit c53e75ef0f
25 changed files with 123 additions and 151 deletions

View File

@ -8,8 +8,6 @@ qualified namespaces io.timeouts io.encodings.utf8 accessors ;
QUALIFIED: io
IN: io.unix.backend
MIXIN: unix-io
! I/O tasks
TUPLE: io-task port callbacks ;
@ -120,7 +118,7 @@ M: integer close-handle ( fd -- )
[ dup reads>> handle-timeout ]
[ dup writes>> handle-timeout ] 2bi ;
M: unix-io cancel-io ( port -- )
M: unix cancel-io ( port -- )
mx get-global cancel-io-tasks ;
! Readers
@ -180,10 +178,10 @@ M: write-task do-io-task
M: port port-flush ( port -- )
dup buffer-empty? [ drop ] [ (wait-to-write) ] if ;
M: unix-io io-multiplex ( ms/f -- )
M: unix io-multiplex ( ms/f -- )
mx get-global wait-for-events ;
M: unix-io (init-stdio) ( -- )
M: unix (init-stdio) ( -- )
0 <reader>
1 <writer>
2 <writer> ;

View File

@ -3,7 +3,7 @@
IN: io.unix.bsd
USING: io.backend io.unix.backend io.unix.kqueue io.unix.select
io.launcher io.unix.launcher namespaces kernel assocs
threads continuations ;
threads continuations system ;
! On Mac OS X, we use select() for the top-level
! multiplexer, and we hang a kqueue off of it for process exit
@ -12,16 +12,12 @@ threads continuations ;
! kqueue is buggy with files and ptys so we can't use it as the
! main multiplexer.
MIXIN: bsd-io
INSTANCE: bsd-io unix-io
M: bsd-io init-io ( -- )
M: bsd init-io ( -- )
<select-mx> mx set-global
<kqueue-mx> kqueue-mx set-global
kqueue-mx get-global <mx-port> <mx-task> dup io-task-fd
2dup mx get-global mx-reads set-at
mx get-global mx-writes set-at ;
M: bsd-io register-process ( process -- )
M: bsd register-process ( process -- )
process-handle kqueue-mx get-global add-pid-task ;

View File

@ -3,15 +3,15 @@
USING: io.backend io.nonblocking io.unix.backend io.files io
unix unix.stat unix.time kernel math continuations
math.bitfields byte-arrays alien combinators calendar
io.encodings.binary accessors sequences strings ;
io.encodings.binary accessors sequences strings system ;
IN: io.unix.files
M: unix-io cwd ( -- path )
M: unix cwd ( -- path )
MAXPATHLEN [ <byte-array> ] [ ] bi getcwd
[ (io-error) ] unless* ;
M: unix-io cd ( path -- )
M: unix cd ( path -- )
chdir io-error ;
: read-flags O_RDONLY ; inline
@ -19,7 +19,7 @@ M: unix-io cd ( path -- )
: open-read ( path -- fd )
O_RDONLY file-mode open dup io-error ;
M: unix-io (file-reader) ( path -- stream )
M: unix (file-reader) ( path -- stream )
open-read <reader> ;
: write-flags { O_WRONLY O_CREAT O_TRUNC } flags ; inline
@ -27,7 +27,7 @@ M: unix-io (file-reader) ( path -- stream )
: open-write ( path -- fd )
write-flags file-mode open dup io-error ;
M: unix-io (file-writer) ( path -- stream )
M: unix (file-writer) ( path -- stream )
open-write <writer> ;
: append-flags { O_WRONLY O_APPEND O_CREAT } flags ; inline
@ -36,28 +36,28 @@ M: unix-io (file-writer) ( path -- stream )
append-flags file-mode open dup io-error
[ dup 0 SEEK_END lseek io-error ] [ ] [ close ] cleanup ;
M: unix-io (file-appender) ( path -- stream )
M: unix (file-appender) ( path -- stream )
open-append <writer> ;
: touch-mode ( -- n )
{ O_WRONLY O_APPEND O_CREAT O_EXCL } flags ; foldable
M: unix-io touch-file ( path -- )
M: unix touch-file ( path -- )
normalize-path
touch-mode file-mode open
dup 0 < [ err_no EEXIST = [ err_no io-error ] unless ] when
close ;
M: unix-io move-file ( from to -- )
M: unix move-file ( from to -- )
[ normalize-path ] bi@ rename io-error ;
M: unix-io delete-file ( path -- )
M: unix delete-file ( path -- )
normalize-path unlink io-error ;
M: unix-io make-directory ( path -- )
M: unix make-directory ( path -- )
normalize-path OCT: 777 mkdir io-error ;
M: unix-io delete-directory ( path -- )
M: unix delete-directory ( path -- )
normalize-path rmdir io-error ;
: (copy-file) ( from to -- )
@ -68,7 +68,7 @@ M: unix-io delete-directory ( path -- )
] with-disposal
] with-disposal ;
M: unix-io copy-file ( from to -- )
M: unix copy-file ( from to -- )
[ normalize-path ] bi@
[ (copy-file) ]
[ swap file-info file-info-permissions chmod io-error ]
@ -95,16 +95,16 @@ M: unix-io copy-file ( from to -- )
} cleave
\ file-info construct-boa ;
M: unix-io file-info ( path -- info )
M: unix file-info ( path -- info )
normalize-path stat* stat>file-info ;
M: unix-io link-info ( path -- info )
M: unix link-info ( path -- info )
normalize-path lstat* stat>file-info ;
M: unix-io make-link ( path1 path2 -- )
M: unix make-link ( path1 path2 -- )
normalize-path symlink io-error ;
M: unix-io read-link ( path -- path' )
M: unix read-link ( path -- path' )
normalize-path
PATH_MAX [ <byte-array> tuck ] [ ] bi readlink
dup io-error head-slice >string ;

View File

@ -1,11 +1,11 @@
USING: kernel io.nonblocking io.unix.backend math.bitfields
unix io.files.unique.backend ;
unix io.files.unique.backend system ;
IN: io.unix.files.unique
: open-unique-flags ( -- flags )
{ O_RDWR O_CREAT O_EXCL } flags ;
M: unix-io (make-unique-file) ( path -- )
M: unix (make-unique-file) ( path -- )
open-unique-flags file-mode open dup io-error close ;
M: unix-io temporary-path ( -- path ) "/tmp" ;
M: unix temporary-path ( -- path ) "/tmp" ;

View File

@ -1,8 +1,3 @@
IN: io.unix.freebsd
USING: io.unix.bsd io.backend ;
USING: io.unix.bsd io.backend system ;
TUPLE: freebsd-io ;
INSTANCE: freebsd-io bsd-io
T{ freebsd-io } set-io-backend
freebsd set-io-backend

View File

@ -79,12 +79,12 @@ USE: unix
(io-error)
] [ 255 exit ] recover ;
M: unix-io current-process-handle ( -- handle ) getpid ;
M: unix current-process-handle ( -- handle ) getpid ;
M: unix-io run-process* ( process -- pid )
M: unix run-process* ( process -- pid )
[ spawn-process ] curry [ ] with-fork ;
M: unix-io kill-process* ( pid -- )
M: unix kill-process* ( pid -- )
SIGTERM kill io-error ;
: open-pipe ( -- pair )
@ -95,7 +95,7 @@ M: unix-io kill-process* ( pid -- )
2dup first close second close
>r first 0 dup2 drop r> second 1 dup2 drop ;
M: unix-io (process-stream)
M: unix (process-stream)
>r open-pipe open-pipe r>
[ >r setup-stdio-pipe r> spawn-process ] curry
[ -rot 2dup second close first close ]

View File

@ -7,10 +7,6 @@ namespaces threads continuations init math alien.c-types alien
vocabs.loader accessors ;
IN: io.unix.linux
TUPLE: linux-io ;
INSTANCE: linux-io unix-io
TUPLE: linux-monitor ;
: <linux-monitor> ( wd -- monitor )
@ -50,7 +46,7 @@ TUPLE: inotify watches ;
"inotify is not supported by this Linux release" throw
] unless ;
M: linux-io <monitor> ( path recursive? -- monitor )
M: linux <monitor> ( path recursive? -- monitor )
check-inotify
drop IN_CHANGE_EVENTS add-watch ;
@ -116,11 +112,11 @@ TUPLE: inotify-task ;
M: inotify-task do-io-task ( task -- )
io-task-port read-notifications f ;
M: linux-io init-io ( -- )
M: linux init-io ( -- )
<select-mx>
[ mx set-global ]
[ [ init-inotify ] curry ignore-errors ] bi ;
T{ linux-io } set-io-backend
linux set-io-backend
[ start-wait-thread ] "io.unix.linux" add-init-hook

View File

@ -1,13 +1,9 @@
IN: io.unix.macosx
USING: io.unix.bsd io.backend io.monitors io.monitors.private
continuations kernel core-foundation.fsevents sequences
namespaces arrays ;
namespaces arrays system ;
IN: io.unix.macosx
TUPLE: macosx-io ;
INSTANCE: macosx-io bsd-io
T{ macosx-io } set-io-backend
macosx set-io-backend
TUPLE: macosx-monitor ;
@ -16,7 +12,7 @@ TUPLE: macosx-monitor ;
[ [ first { +modify-file+ } swap changed-file ] each ] bind
notify-callback ;
M: macosx-io <monitor>
M: macosx <monitor>
drop
f macosx-monitor construct-simple-monitor
dup [ enqueue-notifications ] curry

View File

@ -1,8 +1,3 @@
IN: io.unix.netbsd
USING: io.unix.bsd io.backend ;
USING: io.backend system ;
TUPLE: netbsd-io ;
INSTANCE: netbsd-io bsd-io
T{ netbsd-io } set-io-backend
netbsd set-io-backend

View File

@ -1,8 +1,3 @@
IN: io.unix.openbsd
USING: io.unix.bsd io.backend core-foundation.fsevents ;
USING: io.unix.bsd io.backend core-foundation.fsevents system ;
TUPLE: openbsd-io ;
INSTANCE: openbsd-io bsd-io
T{ openbsd-io } set-io-backend
openbsd set-io-backend

View File

@ -7,10 +7,10 @@ IN: io.windows.ce.backend
: port-errored ( port -- )
win32-error-string swap set-port-error ;
M: windows-ce-io io-multiplex ( ms -- )
M: wince io-multiplex ( ms -- )
60 60 * 1000 * or (sleep) ;
M: windows-ce-io add-completion ( handle -- ) drop ;
M: wince add-completion ( handle -- ) drop ;
GENERIC: wince-read ( port port-handle -- )
@ -26,14 +26,14 @@ M: port port-flush
dup dup port-handle wince-write port-flush
] if ;
M: windows-ce-io init-io ( -- )
M: wince init-io ( -- )
init-winsock ;
LIBRARY: libc
FUNCTION: void* _getstdfilex int fd ;
FUNCTION: void* _fileno void* file ;
M: windows-ce-io (init-stdio) ( -- )
M: wince (init-stdio) ( -- )
#! We support Windows NT too, to make this I/O backend
#! easier to debug.
512 default-buffer-size [

View File

@ -1,7 +1,11 @@
USING: io.backend io.windows io.windows.ce.backend
io.windows.ce.files io.windows.ce.sockets io.windows.ce.launcher
namespaces io.windows.mmap ;
IN: io.windows.ce
USE: io.backend
USE: io.windows
USE: io.windows.ce.backend
USE: io.windows.ce.files
USE: io.windows.ce.sockets
USE: io.windows.ce.launcher
USE: io.windows.mmap system
USE: io.windows.files
T{ windows-ce-io } set-io-backend
USE: system
wince set-io-backend

View File

@ -1,15 +1,15 @@
USING: alien alien.c-types combinators io io.backend io.buffers
io.files io.nonblocking io.windows kernel libc math namespaces
prettyprint sequences strings threads threads.private
windows windows.kernel32 io.windows.ce.backend ;
windows windows.kernel32 io.windows.ce.backend system ;
IN: windows.ce.files
! M: windows-ce-io normalize-path ( string -- string )
! M: wince normalize-path ( string -- string )
! dup 1 tail* CHAR: \\ = [ "*" append ] [ "\\*" append ] if ;
M: windows-ce-io CreateFile-flags ( DWORD -- DWORD )
M: wince CreateFile-flags ( DWORD -- DWORD )
FILE_ATTRIBUTE_NORMAL bitor ;
M: windows-ce-io FileArgs-overlapped ( port -- f ) drop f ;
M: wince FileArgs-overlapped ( port -- f ) drop f ;
: finish-read ( port status bytes-ret -- )
swap [ drop port-errored ] [ swap n>buffer ] if ;

View File

@ -2,11 +2,11 @@ USING: alien alien.c-types combinators io io.backend io.buffers
io.nonblocking io.sockets io.sockets.impl io.windows kernel libc
math namespaces prettyprint qualified sequences strings threads
threads.private windows windows.kernel32 io.windows.ce.backend
byte-arrays ;
byte-arrays system ;
QUALIFIED: windows.winsock
IN: io.windows.ce
M: windows-ce-io WSASocket-flags ( -- DWORD ) 0 ;
M: wince WSASocket-flags ( -- DWORD ) 0 ;
M: win32-socket wince-read ( port port-handle -- )
win32-file-handle over buffer-end pick buffer-capacity 0
@ -31,15 +31,15 @@ M: win32-socket wince-write ( port port-handle -- )
windows.winsock:WSAConnect
windows.winsock:winsock-error!=0/f ;
M: windows-ce-io (client) ( addrspec -- reader writer )
M: wince (client) ( addrspec -- reader writer )
do-connect <win32-socket> dup <reader&writer> ;
M: windows-ce-io (server) ( addrspec -- handle )
M: wince (server) ( addrspec -- handle )
windows.winsock:SOCK_STREAM server-fd
dup listen-on-socket
<win32-socket> ;
M: windows-ce-io (accept) ( server -- client )
M: wince (accept) ( server -- client )
[
dup check-server-port
[
@ -55,7 +55,7 @@ M: windows-ce-io (accept) ( server -- client )
<win32-socket> <reader&writer>
] with-timeout ;
M: windows-ce-io <datagram> ( addrspec -- datagram )
M: wince <datagram> ( addrspec -- datagram )
[
windows.winsock:SOCK_DGRAM server-fd <win32-socket>
] keep <datagram-port> ;
@ -81,7 +81,7 @@ M: windows-ce-io <datagram> ( addrspec -- datagram )
packet-size <byte-array> receive-buffer set-global
M: windows-ce-io receive ( datagram -- packet addrspec )
M: wince receive ( datagram -- packet addrspec )
dup check-datagram-port
[
port-handle win32-file-handle
@ -104,7 +104,7 @@ M: windows-ce-io receive ( datagram -- packet addrspec )
dup length receive-buffer rot pick memcpy
receive-buffer make-WSABUF ;
M: windows-ce-io send ( packet addrspec datagram -- )
M: wince send ( packet addrspec datagram -- )
3dup check-datagram-send
port-handle win32-file-handle
rot send-WSABUF

View File

@ -3,7 +3,7 @@
USING: alien.c-types io.backend io.files io.windows kernel math
windows windows.kernel32 windows.time calendar combinators
math.functions sequences namespaces words symbols
combinators.lib io.nonblocking destructors ;
combinators.lib io.nonblocking destructors system ;
IN: io.windows.files
SYMBOLS: +read-only+ +hidden+ +system+
@ -88,10 +88,10 @@ SYMBOLS: +read-only+ +hidden+ +system+
get-file-information BY_HANDLE_FILE_INFORMATION>file-info
] if ;
M: windows-nt-io file-info ( path -- info )
M: winnt file-info ( path -- info )
normalize-path get-file-information-stat ;
M: windows-nt-io link-info ( path -- info )
M: winnt link-info ( path -- info )
file-info ;
: file-times ( path -- timestamp timestamp timestamp )
@ -125,7 +125,7 @@ M: windows-nt-io link-info ( path -- info )
: set-file-write-time ( path timestamp -- )
>r f f r> set-file-times ;
M: windows-nt-io touch-file ( path -- )
M: winnt touch-file ( path -- )
[
normalize-path
maybe-create-file over close-always

View File

@ -2,9 +2,9 @@ USING: kernel system io.files.unique.backend
windows.kernel32 io.windows io.nonblocking windows ;
IN: io.windows.files.unique
M: windows-io (make-unique-file) ( path -- )
M: windows (make-unique-file) ( path -- )
GENERIC_WRITE CREATE_NEW 0 open-file
CloseHandle win32-error=0/f ;
M: windows-io temporary-path ( -- path )
M: windows temporary-path ( -- path )
"TEMP" os-env ;

View File

@ -101,7 +101,7 @@ TUPLE: CreateProcess-args
HOOK: fill-redirection io-backend ( process args -- )
M: windows-ce-io fill-redirection 2drop ;
M: wince fill-redirection 2drop ;
: make-CreateProcess-args ( process -- args )
default-CreateProcess-args
@ -111,10 +111,10 @@ M: windows-ce-io fill-redirection 2drop ;
fill-startup-info
nip ;
M: windows-io current-process-handle ( -- handle )
M: windows current-process-handle ( -- handle )
GetCurrentProcessId ;
M: windows-io run-process* ( process -- handle )
M: windows run-process* ( process -- handle )
[
dup make-CreateProcess-args
tuck fill-redirection
@ -122,7 +122,7 @@ M: windows-io run-process* ( process -- handle )
lpProcessInformation>>
] with-destructors ;
M: windows-io kill-process* ( handle -- )
M: windows kill-process* ( handle -- )
PROCESS_INFORMATION-hProcess
255 TerminateProcess win32-error=0/f ;
@ -161,7 +161,7 @@ SYMBOL: wait-flag
<flag> wait-flag set-global
[ wait-loop t ] "Process wait" spawn-server drop ;
M: windows-io register-process
M: windows register-process
drop wait-flag get-global raise-flag ;
[ start-wait-thread ] "io.windows.launcher" add-init-hook

View File

@ -1,7 +1,7 @@
USING: alien alien.c-types alien.syntax arrays continuations
destructors generic io.mmap io.nonblocking io.windows
kernel libc math namespaces quotations sequences windows
windows.advapi32 windows.kernel32 io.backend ;
windows.advapi32 windows.kernel32 io.backend system ;
IN: io.windows.mmap
TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
@ -53,11 +53,11 @@ TYPEDEF: TOKEN_PRIVILEGES* PTOKEN_PRIVILEGES
HOOK: with-privileges io-backend ( seq quot -- ) inline
M: windows-nt-io with-privileges
M: winnt with-privileges
over [ [ t set-privilege ] each ] curry compose
swap [ [ f set-privilege ] each ] curry [ ] cleanup ;
M: windows-ce-io with-privileges
M: wince with-privileges
nip call ;
: mmap-open ( path access-mode create-mode flProtect access -- handle handle address )
@ -70,7 +70,7 @@ M: windows-ce-io with-privileges
dup close-later
] with-privileges ;
M: windows-io <mapped-file> ( path length -- mmap )
M: windows <mapped-file> ( path length -- mmap )
[
swap
GENERIC_WRITE GENERIC_READ bitor
@ -81,7 +81,7 @@ M: windows-io <mapped-file> ( path length -- mmap )
f \ mapped-file construct-boa
] with-destructors ;
M: windows-io close-mapped-file ( mapped-file -- )
M: windows close-mapped-file ( mapped-file -- )
[
dup mapped-file-handle [ close-always ] each
mapped-file-address UnmapViewOfFile win32-error=0/f

View File

@ -3,7 +3,7 @@ continuations destructors io io.backend io.nonblocking
io.windows libc kernel math namespaces sequences
threads classes.tuple.lib windows windows.errors
windows.kernel32 strings splitting io.files qualified ascii
combinators.lib ;
combinators.lib system ;
QUALIFIED: windows.winsock
IN: io.windows.nt.backend
@ -28,7 +28,7 @@ SYMBOL: master-completion-port
: <master-completion-port> ( -- handle )
INVALID_HANDLE_VALUE f <completion-port> ;
M: windows-nt-io add-completion ( handle -- )
M: winnt add-completion ( handle -- )
master-completion-port get-global <completion-port> drop ;
: eof? ( error -- ? )
@ -89,13 +89,13 @@ M: windows-nt-io add-completion ( handle -- )
: drain-overlapped ( timeout -- )
handle-overlapped [ 0 drain-overlapped ] unless ;
M: windows-nt-io cancel-io
M: winnt cancel-io
port-handle win32-file-handle CancelIo drop ;
M: windows-nt-io io-multiplex ( ms -- )
M: winnt io-multiplex ( ms -- )
drain-overlapped ;
M: windows-nt-io init-io ( -- )
M: winnt init-io ( -- )
<master-completion-port> master-completion-port set-global
H{ } clone io-hash set-global
windows.winsock:init-winsock ;

View File

@ -1,22 +1,22 @@
USING: continuations destructors io.buffers io.files io.backend
io.timeouts io.nonblocking io.windows io.windows.nt.backend
kernel libc math threads windows windows.kernel32
kernel libc math threads windows windows.kernel32 system
alien.c-types alien.arrays sequences combinators combinators.lib
sequences.lib ascii splitting alien strings assocs namespaces ;
IN: io.windows.nt.files
M: windows-nt-io cwd
M: winnt cwd
MAX_UNICODE_PATH dup "ushort" <c-array>
[ GetCurrentDirectory win32-error=0/f ] keep
alien>u16-string ;
M: windows-nt-io cd
M: winnt cd
SetCurrentDirectory win32-error=0/f ;
: unicode-prefix ( -- seq )
"\\\\?\\" ; inline
M: windows-nt-io root-directory? ( path -- ? )
M: winnt root-directory? ( path -- ? )
{
{ [ dup empty? ] [ f ] }
{ [ dup [ path-separator? ] all? ] [ t ] }
@ -40,15 +40,15 @@ ERROR: not-absolute-path ;
unicode-prefix prepend
] unless ;
M: windows-nt-io normalize-path ( string -- string' )
M: winnt normalize-path ( string -- string' )
(normalize-path)
{ { CHAR: / CHAR: \\ } } substitute
prepend-prefix ;
M: windows-nt-io CreateFile-flags ( DWORD -- DWORD )
M: winnt CreateFile-flags ( DWORD -- DWORD )
FILE_FLAG_OVERLAPPED bitor ;
M: windows-nt-io FileArgs-overlapped ( port -- overlapped )
M: winnt FileArgs-overlapped ( port -- overlapped )
make-overlapped ;
: update-file-ptr ( n port -- )

View File

@ -112,13 +112,13 @@ IN: io.windows.nt.launcher
dup pipe-out f set-inherit
>>stdin-pipe ;
M: windows-nt-io fill-redirection ( process args -- )
M: winnt fill-redirection ( process args -- )
[ 2dup redirect-stdout ] keep lpStartupInfo>> set-STARTUPINFO-hStdOutput
[ 2dup redirect-stderr ] keep lpStartupInfo>> set-STARTUPINFO-hStdError
[ 2dup redirect-stdin ] keep lpStartupInfo>> set-STARTUPINFO-hStdInput
2drop ;
M: windows-nt-io (process-stream)
M: winnt (process-stream)
[
dup make-CreateProcess-args

View File

@ -5,7 +5,7 @@ io.windows.nt.backend kernel math windows windows.kernel32
windows.types libc assocs alien namespaces continuations
io.monitors io.monitors.private io.nonblocking io.buffers
io.files io.timeouts io sequences hashtables sorting arrays
combinators math.bitfields strings ;
combinators math.bitfields strings system ;
IN: io.windows.nt.monitors
: open-directory ( path -- handle )
@ -30,7 +30,7 @@ TUPLE: win32-monitor path recursive? ;
set-delegate
} win32-monitor construct ;
M: windows-nt-io <monitor> ( path recursive? -- monitor )
M: winnt <monitor> ( path recursive? -- monitor )
[
over open-directory win32-monitor <buffered-port>
<win32-monitor>

View File

@ -11,5 +11,6 @@ USE: io.windows.nt.sockets
USE: io.windows.mmap
USE: io.windows.files
USE: io.backend
USE: system
T{ windows-nt-io } set-io-backend
winnt set-io-backend

View File

@ -2,13 +2,13 @@ USING: alien alien.accessors alien.c-types byte-arrays
continuations destructors io.nonblocking io.timeouts io.sockets
io.sockets.impl io namespaces io.streams.duplex io.windows
io.windows.nt.backend windows.winsock kernel libc math sequences
threads classes.tuple.lib ;
threads classes.tuple.lib system ;
IN: io.windows.nt.sockets
: malloc-int ( object -- object )
"int" heap-size malloc tuck 0 set-alien-signed-4 ; inline
M: windows-nt-io WSASocket-flags ( -- DWORD )
M: winnt WSASocket-flags ( -- DWORD )
WSA_FLAG_OVERLAPPED ;
: get-ConnectEx-ptr ( socket -- void* )
@ -50,7 +50,7 @@ TUPLE: ConnectEx-args port
2dup save-callback
get-overlapped-result drop ;
M: windows-nt-io (client) ( addrspec -- client-in client-out )
M: winnt (client) ( addrspec -- client-in client-out )
[
\ ConnectEx-args construct-empty
over make-sockaddr/size pick init-connect
@ -119,7 +119,7 @@ TUPLE: AcceptEx-args port
[ AcceptEx-args-sAcceptSocket* add-completion ] keep
AcceptEx-args-sAcceptSocket* <win32-socket> ;
M: windows-nt-io (accept) ( server -- addrspec handle )
M: winnt (accept) ( server -- addrspec handle )
[
[
dup check-server-port
@ -131,14 +131,14 @@ M: windows-nt-io (accept) ( server -- addrspec handle )
] with-timeout
] with-destructors ;
M: windows-nt-io (server) ( addrspec -- handle )
M: winnt (server) ( addrspec -- handle )
[
SOCK_STREAM server-fd dup listen-on-socket
dup add-completion
<win32-socket>
] with-destructors ;
M: windows-nt-io <datagram> ( addrspec -- datagram )
M: winnt <datagram> ( addrspec -- datagram )
[
[
SOCK_DGRAM server-fd
@ -190,7 +190,7 @@ TUPLE: WSARecvFrom-args port
[ WSARecvFrom-args-lpFrom* ] keep
WSARecvFrom-args-port datagram-port-addr parse-sockaddr ;
M: windows-nt-io receive ( datagram -- packet addrspec )
M: winnt receive ( datagram -- packet addrspec )
[
dup check-datagram-port
\ WSARecvFrom-args construct-empty
@ -242,7 +242,7 @@ TUPLE: WSASendTo-args port
USE: io.sockets
M: windows-nt-io send ( packet addrspec datagram -- )
M: winnt send ( packet addrspec datagram -- )
[
3dup check-datagram-send
\ WSASendTo-args construct-empty

View File

@ -5,16 +5,12 @@ io.buffers io.files io.nonblocking io.sockets io.binary
io.sockets.impl windows.errors strings io.streams.duplex
kernel math namespaces sequences windows windows.kernel32
windows.shell32 windows.types windows.winsock splitting
continuations math.bitfields ;
continuations math.bitfields system ;
IN: io.windows
TUPLE: windows-nt-io ;
TUPLE: windows-ce-io ;
UNION: windows-io windows-nt-io windows-ce-io ;
M: windows destruct-handle CloseHandle drop ;
M: windows-io destruct-handle CloseHandle drop ;
M: windows-io destruct-socket closesocket drop ;
M: windows destruct-socket closesocket drop ;
TUPLE: win32-file handle ptr ;
@ -24,7 +20,7 @@ HOOK: CreateFile-flags io-backend ( DWORD -- DWORD )
HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f )
HOOK: add-completion io-backend ( port -- )
M: windows-io normalize-directory ( string -- string )
M: windows normalize-directory ( string -- string )
normalize-path "\\" ?tail drop "\\*" append ;
: share-mode ( -- fixnum )
@ -125,30 +121,30 @@ C: <FileArgs> FileArgs
[ FileArgs-lpNumberOfBytesRet ] keep
FileArgs-lpOverlapped ;
M: windows-io (file-reader) ( path -- stream )
M: windows (file-reader) ( path -- stream )
open-read <win32-file> <reader> ;
M: windows-io (file-writer) ( path -- stream )
M: windows (file-writer) ( path -- stream )
open-write <win32-file> <writer> ;
M: windows-io (file-appender) ( path -- stream )
M: windows (file-appender) ( path -- stream )
open-append <win32-file> <writer> ;
M: windows-io move-file ( from to -- )
M: windows move-file ( from to -- )
[ normalize-path ] bi@ MoveFile win32-error=0/f ;
M: windows-io delete-file ( path -- )
M: windows delete-file ( path -- )
normalize-path DeleteFile win32-error=0/f ;
M: windows-io copy-file ( from to -- )
M: windows copy-file ( from to -- )
dup parent-directory make-directories
[ normalize-path ] bi@ 0 CopyFile win32-error=0/f ;
M: windows-io make-directory ( path -- )
M: windows make-directory ( path -- )
normalize-path
f CreateDirectory win32-error=0/f ;
M: windows-io delete-directory ( path -- )
M: windows delete-directory ( path -- )
normalize-path
RemoveDirectory win32-error=0/f ;
@ -194,7 +190,7 @@ USE: namespaces
M: win32-socket dispose ( stream -- )
win32-file-handle closesocket drop ;
M: windows-io addrinfo-error ( n -- )
M: windows addrinfo-error ( n -- )
winsock-return-check ;
: tcp-socket ( addrspec -- socket )