]> gitweb.factorcode.org Git - factor.git/blob - basis/io/sockets/secure/unix/unix.factor
io.sockets.secure.unix: refactor (shutdown)
[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 destructors io.backend.unix io.files
4 io.sockets.private io.sockets.secure io.sockets.secure.openssl
5 io.timeouts kernel openssl openssl.libssl system ;
6 FROM: io.ports => shutdown ;
7 IN: io.sockets.secure.unix
8
9 M: openssl ssl-supported? t ;
10 M: openssl ssl-certificate-verification-supported? t ;
11
12 M: ssl-handle handle-fd file>> handle-fd ;
13
14 M: unix socket-handle fd>> ;
15
16 M: secure remote>handle
17     [ addrspec>> remote>handle ] [ hostname>> ] bi <ssl-socket> ;
18
19 M: secure parse-sockaddr addrspec>> parse-sockaddr f <secure> ;
20
21 M: secure (get-local-address) addrspec>> (get-local-address) ;
22
23 M: secure establish-connection
24     addrspec>> [ establish-connection ] [ secure-connection ] 2bi ;
25
26 M: secure (accept)
27     [
28         addrspec>> (accept) [ |dispose f <ssl-socket> ] dip
29     ] with-destructors ;
30
31 : (shutdown) ( ssl-handle -- )
32     dup dup handle>> SSL_shutdown check-ssl-error
33     [ dupd wait-for-fd (shutdown) ] [ drop ] if* ;
34
35 M: ssl-handle shutdown
36     dup connected>> [
37         f >>connected [ (shutdown) ] with-timeout
38     ] [ drop ] if ;
39
40 M: unix non-ssl-socket? fd? ;