USING: accessors alien alien.c-types alien.data alien.strings
alien.syntax arrays assocs classes.struct combinators
combinators.short-circuit continuations destructors environment
-io io.backend io.binary io.buffers io.encodings.utf16n io.files
+fry io io.backend io.binary io.buffers io.encodings.utf16n io.files
io.files.private io.files.types io.pathnames io.ports
io.streams.c io.streams.null io.timeouts kernel libc literals
locals make math math.bitwise namespaces sequences
specialized-arrays system threads tr windows windows.errors
windows.handles windows.kernel32 windows.shell32 windows.time
-windows.types fry ;
+windows.types windows.winsock ;
SPECIALIZED-ARRAY: ushort
IN: io.files.windows
M: windows (wait-to-read) ( port -- )
[ dup handle>> refill ] with-destructors drop ;
+: make-fd-set ( socket -- fd_set )
+ fd_set <struct> swap 1array void* >c-array >>fd_array 1 >>fd_count ;
+
+: select-sets ( socket event -- read-fds write-fds except-fds )
+ [ make-fd-set ] dip +input+ = [ f f ] [ f swap f ] if ;
+
+CONSTANT: select-timeval S{ timeval { sec 0 } { usec 1000 } }
+
M: windows wait-for-fd ( handle event -- )
- 2drop ;
+ [ file>> handle>> 1 swap ] dip select-sets select-timeval
+ select drop yield ;
: console-app? ( -- ? ) GetConsoleWindow >boolean ;
-USING:
- accessors
- alien
- io.ports
- io.sockets.private io.sockets.secure io.sockets.secure.openssl
- kernel
- openssl openssl.libcrypto openssl.libssl ;
+USING: accessors alien io.ports io.sockets.private io.sockets.secure
+io.sockets.secure.openssl io.sockets.windows kernel locals openssl
+openssl.libcrypto openssl.libssl windows.winsock ;
IN: io.sockets.secure.windows
M: openssl ssl-supported? t ;
M: secure parse-sockaddr addrspec>> parse-sockaddr <secure> ;
-M: secure establish-connection ( client-out remote -- )
- [
- [ handle>> file>> <output-port> ] [ addrspec>> ] bi* establish-connection
- ]
- [ secure-connection ] 2bi ;
+M:: secure establish-connection ( client-out addrspec -- )
+ client-out handle>> file>> :> socket
+ socket FIONBIO 1 set-ioctl-socket
+ socket <output-port> addrspec addrspec>> establish-connection
+ client-out addrspec secure-connection
+ socket FIONBIO 0 set-ioctl-socket ;