From c077a38649d3780b8cead8aa554542476ec46d11 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Tue, 20 May 2008 18:52:11 -0500 Subject: [PATCH] Check if fd has been closed for sanity --- extra/io/ports/ports.factor | 6 +++--- extra/io/unix/backend/backend.factor | 15 +++++++++------ extra/io/unix/sockets/secure/secure.factor | 3 +++ extra/io/windows/nt/backend/backend.factor | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/extra/io/ports/ports.factor b/extra/io/ports/ports.factor index b82797354f..e3c873e9d0 100755 --- a/extra/io/ports/ports.factor +++ b/extra/io/ports/ports.factor @@ -115,11 +115,11 @@ M: buffered-port dispose* [ [ [ buffer-free ] when* f ] change-buffer drop ] bi ; -HOOK: cancel-io io-backend ( port -- ) +GENERIC: cancel-io ( handle -- ) -M: port timed-out cancel-io ; +M: port timed-out handle>> cancel-io ; -M: port dispose* [ cancel-io ] [ handle>> dispose ] bi ; +M: port dispose* handle>> [ cancel-io ] [ dispose ] bi ; : ( read-handle write-handle -- input-port output-port ) [ diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index 8f5b6c7540..723ce8b255 100755 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -25,7 +25,7 @@ TUPLE: fd fd disposed ; M: fd dispose* fd>> close-file ; -M: fd handle-fd fd>> ; +M: fd handle-fd dup check-disposed fd>> ; ! I/O multiplexers TUPLE: mx fd reads writes ; @@ -62,11 +62,14 @@ GENERIC: wait-for-events ( ms mx -- ) : output-available ( fd mx -- ) remove-output-callbacks [ resume ] each ; -M: unix cancel-io ( port -- ) - handle>> handle-fd mx get-global - [ remove-input-callbacks [ t swap resume-with ] each ] - [ remove-output-callbacks [ t swap resume-with ] each ] - 2bi ; +M: fd cancel-io ( fd -- ) + dup disposed>> [ drop ] [ + fd>> + mx get-global + [ remove-input-callbacks [ t swap resume-with ] each ] + [ remove-output-callbacks [ t swap resume-with ] each ] + 2bi + ] if ; SYMBOL: +retry+ ! just try the operation again without blocking SYMBOL: +input+ diff --git a/extra/io/unix/sockets/secure/secure.factor b/extra/io/unix/sockets/secure/secure.factor index 35f72a5d16..f3931ae397 100755 --- a/extra/io/unix/sockets/secure/secure.factor +++ b/extra/io/unix/sockets/secure/secure.factor @@ -64,6 +64,9 @@ M: ssl-handle drain SSL_write check-write-response ; +M: ssl-handle cancel-io + file>> cancel-io ; + ! Client sockets : ( fd -- ssl ) [ fd>> BIO_NOCLOSE BIO_new_socket dup ssl-error ] keep diff --git a/extra/io/windows/nt/backend/backend.factor b/extra/io/windows/nt/backend/backend.factor index 5cc0751c55..27fe558642 100755 --- a/extra/io/windows/nt/backend/backend.factor +++ b/extra/io/windows/nt/backend/backend.factor @@ -71,8 +71,8 @@ M: winnt add-completion ( win32-handle -- ) resume-callback t ] if ; -M: winnt cancel-io - handle>> handle>> CancelIo drop ; +M: win32-handle cancel-io + handle>> CancelIo drop ; M: winnt io-multiplex ( ms -- ) handle-overlapped [ 0 io-multiplex ] when ;