1 ! Copyright (C) 2007, 2011, Slava Pestov, Elie CHAFTARI.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors combinators destructors io.backend.unix
4 io.files io.sockets.private io.sockets.secure
5 io.sockets.secure.openssl io.timeouts kernel math openssl
6 openssl.libssl system ;
7 FROM: io.ports => shutdown ;
8 IN: io.sockets.secure.unix
10 M: openssl ssl-supported? t ;
11 M: openssl ssl-certificate-verification-supported? t ;
13 M: ssl-handle handle-fd file>> handle-fd ;
15 M: unix socket-handle fd>> ;
17 M: secure remote>handle
18 [ addrspec>> remote>handle ] [ hostname>> ] bi <ssl-socket> ;
20 M: secure parse-sockaddr addrspec>> parse-sockaddr f <secure> ;
22 M: secure (get-local-address) addrspec>> (get-local-address) ;
24 M: secure establish-connection
25 addrspec>> [ establish-connection ] [ secure-connection ] 2bi ;
29 addrspec>> (accept) [ |dispose f <ssl-socket> ] dip
32 : check-shutdown-response ( handle r -- event )
33 ! We don't do two-step shutdown here because I couldn't
34 ! figure out how to do it with non-blocking BIOs. Also, it
35 ! seems that SSL_shutdown always returns 0 -- this sounds
37 over handle>> over SSL_get_error
39 { SSL_ERROR_NONE [ 2drop f ] }
40 { SSL_ERROR_WANT_READ [ 2drop +input+ ] }
41 { SSL_ERROR_WANT_WRITE [ 2drop +output+ ] }
42 { SSL_ERROR_SYSCALL [ [ drop f ] [ nip syscall-error ] if-zero ] }
43 { SSL_ERROR_SSL [ (ssl-error) ] }
46 : (shutdown) ( handle -- )
47 dup dup handle>> SSL_shutdown check-shutdown-response
48 [ dupd wait-for-fd (shutdown) ] [ drop ] if* ;
50 M: ssl-handle shutdown
52 f >>connected [ (shutdown) ] with-timeout
55 M: unix non-ssl-socket? fd? ;