From a68f50c183ce66355b1a63596966a60156f5b216 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Thu, 15 May 2008 18:14:46 -0500 Subject: [PATCH] Simplify some code --- extra/io/ports/ports-docs.factor | 5 ----- extra/io/ports/ports.factor | 5 +---- extra/io/unix/backend/backend.factor | 19 +++++++++---------- extra/io/unix/pipes/pipes.factor | 3 +-- extra/io/unix/sockets/sockets.factor | 2 +- extra/io/windows/windows.factor | 3 --- extra/openssl/openssl.factor | 2 -- 7 files changed, 12 insertions(+), 27 deletions(-) diff --git a/extra/io/ports/ports-docs.factor b/extra/io/ports/ports-docs.factor index 0db8b01df5..63d1507692 100755 --- a/extra/io/ports/ports-docs.factor +++ b/extra/io/ports/ports-docs.factor @@ -22,7 +22,6 @@ $nl { $subsection init-stdio } { $subsection io-multiplex } "Per-port native I/O protocol:" -{ $subsection init-handle } { $subsection (wait-to-read) } { $subsection (wait-to-write) } "Additionally, the I/O backend must provide an implementation of the " { $link dispose } " generic word." ; @@ -46,10 +45,6 @@ HELP: input-port HELP: output-port { $class-description "The class of ports implementing the output stream protocol." } ; -HELP: init-handle -{ $values { "handle" "a native handle identifying an I/O resource" } } -{ $contract "Prepares a native handle for use by the port; called by " { $link } "." } ; - HELP: { $values { "handle" "a native handle identifying an I/O resource" } { "class" class } { "port" "a new " { $link port } } } { $description "Creates a new " { $link port } " with no buffer." } diff --git a/extra/io/ports/ports.factor b/extra/io/ports/ports.factor index 96492d2f93..d345975441 100755 --- a/extra/io/ports/ports.factor +++ b/extra/io/ports/ports.factor @@ -16,11 +16,8 @@ M: port timeout timeout>> ; M: port set-timeout (>>timeout) ; -GENERIC: init-handle ( handle -- ) - : ( handle class -- port ) - new - swap dup init-handle >>handle ; inline + new swap >>handle ; inline : pending-error ( port -- ) [ f ] change-error drop [ throw ] when* ; diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index f4a3080dd9..2d5ebb98ca 100644 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -13,7 +13,15 @@ GENERIC: handle-fd ( handle -- fd ) TUPLE: fd fd disposed ; -: ( n -- fd ) f fd boa ; +: ( n -- fd ) + #! We drop the error code rather than calling io-error, + #! since on OS X 10.3, this operation fails from init-io + #! when running the Factor.app (presumably because fd 0 and + #! 1 are closed). + [ F_SETFL O_NONBLOCK fcntl drop ] + [ F_SETFD FD_CLOEXEC fcntl drop ] + [ f fd boa ] + tri ; M: fd dispose* fd>> close-file ; @@ -96,15 +104,6 @@ SYMBOL: +output+ : io-error ( n -- ) 0 < [ (io-error) ] when ; -M: fd init-handle ( fd -- ) - #! We drop the error code rather than calling io-error, - #! since on OS X 10.3, this operation fails from init-io - #! when running the Factor.app (presumably because fd 0 and - #! 1 are closed). - fd>> - [ F_SETFL O_NONBLOCK fcntl drop ] - [ F_SETFD FD_CLOEXEC fcntl drop ] bi ; - ! Readers : eof ( reader -- ) dup buffer>> buffer-empty? [ t >>eof ] when drop ; diff --git a/extra/io/unix/pipes/pipes.factor b/extra/io/unix/pipes/pipes.factor index db2c917520..71366bfa4a 100644 --- a/extra/io/unix/pipes/pipes.factor +++ b/extra/io/unix/pipes/pipes.factor @@ -8,5 +8,4 @@ QUALIFIED: io.pipes M: unix io.pipes:(pipe) ( -- pair ) 2 "int" dup pipe io-error - 2 c-int-array> first2 [ ] bi@ - [ [ init-handle ] bi@ ] [ io.pipes:pipe boa ] 2bi ; + 2 c-int-array> first2 [ ] bi@ io.pipes:pipe boa ; diff --git a/extra/io/unix/sockets/sockets.factor b/extra/io/unix/sockets/sockets.factor index 0bb0e3405a..fbeb25800c 100755 --- a/extra/io/unix/sockets/sockets.factor +++ b/extra/io/unix/sockets/sockets.factor @@ -13,7 +13,7 @@ EXCLUDE: io.sockets => accept ; IN: io.unix.sockets : socket-fd ( domain type -- fd ) - 0 socket dup io-error |dispose dup init-handle ; + 0 socket dup io-error |dispose ; : set-socket-option ( fd level opt -- ) >r >r handle-fd r> r> 1 "int" heap-size setsockopt io-error ; diff --git a/extra/io/windows/windows.factor b/extra/io/windows/windows.factor index 6b6b54ab92..30b72f3e2f 100755 --- a/extra/io/windows/windows.factor +++ b/extra/io/windows/windows.factor @@ -24,9 +24,6 @@ TUPLE: win32-file < win32-handle ptr ; : ( handle -- win32-file ) win32-file new-win32-handle ; -M: win32-file init-handle ( handle -- ) - drop ; - HOOK: CreateFile-flags io-backend ( DWORD -- DWORD ) HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f ) HOOK: add-completion io-backend ( port -- ) diff --git a/extra/openssl/openssl.factor b/extra/openssl/openssl.factor index 014592dbcc..695b9a1d7d 100755 --- a/extra/openssl/openssl.factor +++ b/extra/openssl/openssl.factor @@ -133,8 +133,6 @@ M: no-ssl-context summary current-ssl-context handle>> SSL_new dup ssl-error f f ssl-handle boa ; -M: ssl-handle init-handle file>> init-handle ; - HOOK: ssl-shutdown io-backend ( handle -- ) M: ssl-handle dispose*