Fix circular dependency

db4
Slava Pestov 2008-05-12 22:30:18 -05:00
parent eb2cd0b066
commit b94a20cc8a
5 changed files with 32 additions and 35 deletions

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007 Doug Coleman. ! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors continuations io.backend io.nonblocking libc USING: accessors continuations io.backend libc
kernel namespaces sequences system vectors ; kernel namespaces sequences system vectors ;
IN: destructors IN: destructors
@ -49,33 +49,3 @@ M: memory-destructor dispose ( obj -- )
: free-later ( alien -- ) : free-later ( alien -- )
<memory-destructor> <only-once> add-error-destructor ; <memory-destructor> <only-once> add-error-destructor ;
! Handles
TUPLE: handle-destructor alien ;
C: <handle-destructor> handle-destructor
M: handle-destructor dispose ( obj -- )
alien>> close-handle ;
: close-always ( handle -- )
<handle-destructor> <only-once> add-always-destructor ;
: close-later ( handle -- )
<handle-destructor> <only-once> add-error-destructor ;
! Sockets
TUPLE: socket-destructor alien ;
C: <socket-destructor> socket-destructor
HOOK: destruct-socket io-backend ( obj -- )
M: socket-destructor dispose ( obj -- )
alien>> destruct-socket ;
: close-socket-always ( handle -- )
<socket-destructor> <only-once> add-always-destructor ;
: close-socket-later ( handle -- )
<socket-destructor> <only-once> add-error-destructor ;

View File

@ -20,6 +20,19 @@ GENERIC: init-handle ( handle -- )
GENERIC: close-handle ( handle -- ) GENERIC: close-handle ( handle -- )
TUPLE: handle-destructor handle ;
C: <handle-destructor> handle-destructor
M: handle-destructor dispose ( obj -- )
handle>> close-handle ;
: close-always ( handle -- )
<handle-destructor> <only-once> add-always-destructor ;
: close-later ( handle -- )
<handle-destructor> <only-once> add-error-destructor ;
: <port> ( handle class -- port ) : <port> ( handle class -- port )
new new
swap dup init-handle >>handle ; inline swap dup init-handle >>handle ; inline

View File

@ -6,11 +6,13 @@ continuations destructors
openssl openssl.libcrypto openssl.libssl openssl openssl.libcrypto openssl.libssl
io.files io.nonblocking io.unix.backend io.unix.sockets io.files io.nonblocking io.unix.backend io.unix.sockets
io.encodings.ascii io.buffers io.sockets io.sockets.secure io.encodings.ascii io.buffers io.sockets io.sockets.secure
unix.ffi ; unix ;
IN: io.unix.sockets.secure IN: io.unix.sockets.secure
! todo: SSL_pending, rehandshake ! todo: SSL_pending, rehandshake
! do we call write twice, wth 0 bytes at the end? ! do we call write twice, wth 0 bytes at the end?
! check-certificate at some point
! test on windows
M: ssl-handle handle-fd file>> ; M: ssl-handle handle-fd file>> ;

View File

@ -3,9 +3,9 @@
USING: alien alien.c-types alien.strings generic kernel math USING: alien alien.c-types alien.strings generic kernel math
namespaces threads sequences byte-arrays io.nonblocking namespaces threads sequences byte-arrays io.nonblocking
io.binary io.unix.backend io.streams.duplex io.sockets.impl io.binary io.unix.backend io.streams.duplex io.sockets.impl
io.backend io.files io.files.private io.encodings.utf8 io.backend io.nonblocking io.files io.files.private
math.parser continuations libc combinators system accessors io.encodings.utf8 math.parser continuations libc combinators
qualified unix ; system accessors qualified destructors unix ;
EXCLUDE: io => read write close ; EXCLUDE: io => read write close ;
EXCLUDE: io.sockets => accept ; EXCLUDE: io.sockets => accept ;

View File

@ -175,6 +175,18 @@ USE: windows.winsock
[ server-sockaddr ] keep [ server-sockaddr ] keep
sockaddr-type heap-size bind socket-error ; sockaddr-type heap-size bind socket-error ;
TUPLE: socket-destructor alien ;
C: <socket-destructor> socket-destructor
HOOK: destruct-socket io-backend ( obj -- )
M: socket-destructor dispose ( obj -- )
alien>> destruct-socket ;
: close-socket-later ( handle -- )
<socket-destructor> <only-once> add-error-destructor ;
: server-fd ( addrspec type -- fd ) : server-fd ( addrspec type -- fd )
>r dup protocol-family r> open-socket >r dup protocol-family r> open-socket
dup close-socket-later dup close-socket-later