]> gitweb.factorcode.org Git - factor.git/blob - basis/io/sockets/secure/unix/unix.factor
basis: removing unnecessary method stack effects.
[factor.git] / basis / io / sockets / secure / unix / unix.factor
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
9
10 M: openssl ssl-supported? t ;
11 M: openssl ssl-certificate-verification-supported? t ;
12
13 M: ssl-handle handle-fd file>> handle-fd ;
14
15 M: unix socket-handle fd>> ;
16
17 M: secure remote>handle
18     [ addrspec>> remote>handle ] [ hostname>> ] bi <ssl-socket> ;
19
20 M: secure parse-sockaddr addrspec>> parse-sockaddr f <secure> ;
21
22 M: secure (get-local-address) addrspec>> (get-local-address) ;
23
24 M: secure establish-connection
25     addrspec>> [ establish-connection ] [ secure-connection ] 2bi ;
26
27 M: secure (accept)
28     [
29         addrspec>> (accept) [ |dispose f <ssl-socket> ] dip
30     ] with-destructors ;
31
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
36     ! like a bug
37     over handle>> over SSL_get_error
38     {
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) ] }
44     } case ;
45
46 : (shutdown) ( handle -- )
47     dup dup handle>> SSL_shutdown check-shutdown-response
48     [ dupd wait-for-fd (shutdown) ] [ drop ] if* ;
49
50 M: ssl-handle shutdown
51     dup connected>> [
52         f >>connected [ (shutdown) ] with-timeout
53     ] [ drop ] if ;
54
55 M: unix non-ssl-socket? fd? ;