]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge:
authorBjörn Lindqvist <bjourne@gmail.com>
Wed, 2 Apr 2014 15:44:19 +0000 (17:44 +0200)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 2 Apr 2014 17:16:51 +0000 (12:16 -0500)
io.sockets.secure.windows: use non-blocking sockets to prevent
SSL_connect from blocking

On Windows, SSL_connect may hang forever if the server doesn't send any
data. To counteract that we temporarily set the socket non-blocking and
then call select in the wait-for-fd method.

Conflicts:
basis/io/sockets/secure/openssl/openssl-tests.factor

basis/io/files/windows/windows.factor
basis/io/sockets/secure/openssl/openssl-tests.factor
basis/io/sockets/secure/windows/windows.factor
basis/windows/winsock/winsock.factor

index 066da7d46eba0ba2062b26075ec13cc38beaf112..b3f4e866bf9ad8c0df4c530dd1f2f751ca189799 100755 (executable)
@@ -3,13 +3,13 @@
 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
 
@@ -206,8 +206,17 @@ M: windows (wait-to-write) ( port -- )
 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 ;
 
index 525df8017012eed3586749e2855ad58d005c1d05..6ee13c4ced287f61f6f319ec04f6772608f7498f 100644 (file)
@@ -4,6 +4,8 @@ kernel openssl.libcrypto openssl.libssl sequences system tools.test urls
 unix.ffi ;
 IN: io.sockets.secure.openssl.tests
 
+<< os windows? [ "windows.winsock" ] [ "unix.ffi" ] if use-vocab >>
+
 : new-ssl ( -- ssl )
     SSLv23_client_method SSL_CTX_new SSL_new ;
 
index a4887bd14b9d3505ec91dcec70ac105e8c749d52..1f9a2dc8b19115cd8fe613f44a37302af8bf62ad 100644 (file)
@@ -1,10 +1,6 @@
-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 ;
@@ -24,8 +20,9 @@ M: secure (get-local-address) ( handle remote -- sockaddr )
 
 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 ;
index 029003a7621d1ccaaa3f2f255e46d5c474897311..acd235577e35dd55be4aec36c57c67457d682b87 100644 (file)
@@ -159,7 +159,9 @@ M: sockaddr-in sockaddr>ip ( sockaddr -- string )
 M: sockaddr-in6 sockaddr>ip ( uchar-array -- string )
     addr>> [ >hex ] { } map-as 2 group [ concat ] map ":" join ;
 
-C-TYPE: fd_set
+STRUCT: fd_set
+    { fd_count uint }
+    { fd_array SOCKET[64] } ;
 
 LIBRARY: winsock