Simplify some code
parent
f151a448c6
commit
a68f50c183
|
@ -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 <port> } "." } ;
|
||||
|
||||
HELP: <port>
|
||||
{ $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." }
|
||||
|
|
|
@ -16,11 +16,8 @@ M: port timeout timeout>> ;
|
|||
|
||||
M: port set-timeout (>>timeout) ;
|
||||
|
||||
GENERIC: init-handle ( handle -- )
|
||||
|
||||
: <port> ( handle class -- port )
|
||||
new
|
||||
swap dup init-handle >>handle ; inline
|
||||
new swap >>handle ; inline
|
||||
|
||||
: pending-error ( port -- )
|
||||
[ f ] change-error drop [ throw ] when* ;
|
||||
|
|
|
@ -13,7 +13,15 @@ GENERIC: handle-fd ( handle -- fd )
|
|||
|
||||
TUPLE: fd fd disposed ;
|
||||
|
||||
: <fd> ( n -- fd ) f fd boa ;
|
||||
: <fd> ( 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 ;
|
||||
|
|
|
@ -8,5 +8,4 @@ QUALIFIED: io.pipes
|
|||
M: unix io.pipes:(pipe) ( -- pair )
|
||||
2 "int" <c-array>
|
||||
dup pipe io-error
|
||||
2 c-int-array> first2 [ <fd> ] bi@
|
||||
[ [ init-handle ] bi@ ] [ io.pipes:pipe boa ] 2bi ;
|
||||
2 c-int-array> first2 [ <fd> ] bi@ io.pipes:pipe boa ;
|
||||
|
|
|
@ -13,7 +13,7 @@ EXCLUDE: io.sockets => accept ;
|
|||
IN: io.unix.sockets
|
||||
|
||||
: socket-fd ( domain type -- fd )
|
||||
0 socket dup io-error <fd> |dispose dup init-handle ;
|
||||
0 socket dup io-error <fd> |dispose ;
|
||||
|
||||
: set-socket-option ( fd level opt -- )
|
||||
>r >r handle-fd r> r> 1 <int> "int" heap-size setsockopt io-error ;
|
||||
|
|
|
@ -24,9 +24,6 @@ TUPLE: win32-file < win32-handle ptr ;
|
|||
: <win32-file> ( 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 -- )
|
||||
|
|
|
@ -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*
|
||||
|
|
Loading…
Reference in New Issue