Convert native I/O to use inheritance
parent
1625511df7
commit
e794466efb
|
@ -129,9 +129,6 @@ HELP: <process>
|
||||||
{ $values { "process" process } }
|
{ $values { "process" process } }
|
||||||
{ $description "Creates a new, empty process. It must be filled in before being passed to " { $link run-process } "." } ;
|
{ $description "Creates a new, empty process. It must be filled in before being passed to " { $link run-process } "." } ;
|
||||||
|
|
||||||
HELP: process-stream
|
|
||||||
{ $class-description "A bidirectional stream for interacting with a running process. Instances are created by calling " { $link <process-stream> } ". The " { $link process-stream-process } " slot holds a " { $link process } " instance." } ;
|
|
||||||
|
|
||||||
HELP: <process-stream>
|
HELP: <process-stream>
|
||||||
{ $values
|
{ $values
|
||||||
{ "desc" "a launch descriptor" }
|
{ "desc" "a launch descriptor" }
|
||||||
|
@ -144,7 +141,7 @@ HELP: with-process-stream
|
||||||
{ "desc" "a launch descriptor" }
|
{ "desc" "a launch descriptor" }
|
||||||
{ "quot" quotation }
|
{ "quot" quotation }
|
||||||
{ "status" "an exit code" } }
|
{ "status" "an exit code" } }
|
||||||
{ $description "Calls " { $snippet "quot" } " in a dynamic scope where " { $link stdio } " is rebound to a " { $link process-stream } ". After the quotation returns, waits for the process to end and outputs the exit code." } ;
|
{ $description "Calls " { $snippet "quot" } " in a dynamic scope where " { $link stdio } " is rebound to a process stream. After the quotation returns, waits for the process to end and outputs the exit code." } ;
|
||||||
|
|
||||||
HELP: wait-for-process
|
HELP: wait-for-process
|
||||||
{ $values { "process" process } { "status" integer } }
|
{ $values { "process" process } { "status" integer } }
|
||||||
|
|
|
@ -150,18 +150,18 @@ M: process timed-out kill-process ;
|
||||||
|
|
||||||
HOOK: (process-stream) io-backend ( process -- handle in out )
|
HOOK: (process-stream) io-backend ( process -- handle in out )
|
||||||
|
|
||||||
TUPLE: process-stream process ;
|
: <process-stream*> ( desc encoding -- stream process )
|
||||||
|
>r >process dup dup (process-stream) <reader&writer>
|
||||||
|
r> <encoder-duplex> -roll
|
||||||
|
process-started ;
|
||||||
|
|
||||||
: <process-stream> ( desc encoding -- stream )
|
: <process-stream> ( desc encoding -- stream )
|
||||||
>r >process dup dup (process-stream)
|
<process-stream*> drop ; inline
|
||||||
>r >r process-started process-stream construct-boa
|
|
||||||
r> r> <reader&writer> r> <encoder-duplex>
|
|
||||||
over set-delegate ;
|
|
||||||
|
|
||||||
: with-process-stream ( desc quot -- status )
|
: with-process-stream ( desc quot -- status )
|
||||||
swap <process-stream>
|
swap <process-stream*> >r
|
||||||
[ swap with-stream ] keep
|
[ swap with-stream ] keep
|
||||||
process>> wait-for-process ; inline
|
r> wait-for-process ; inline
|
||||||
|
|
||||||
: notify-exit ( process status -- )
|
: notify-exit ( process status -- )
|
||||||
>>status
|
>>status
|
||||||
|
|
|
@ -36,10 +36,10 @@ HELP: port
|
||||||
$nl
|
$nl
|
||||||
"Ports have the following slots:"
|
"Ports have the following slots:"
|
||||||
{ $list
|
{ $list
|
||||||
{ { $link port-handle } " - a native handle identifying the underlying native resource used by the port" }
|
{ { $snippet "handle" } " - a native handle identifying the underlying native resource used by the port" }
|
||||||
{ { $link port-error } " - the most recent I/O error, if any. This error is thrown to the waiting thread when " { $link pending-error } " is called by stream operations" }
|
{ { $snippet "error" } " - the most recent I/O error, if any. This error is thrown to the waiting thread when " { $link pending-error } " is called by stream operations" }
|
||||||
{ { $link port-type } " - a symbol identifying the port's intended purpose" }
|
{ { $snippet "type" } " - a symbol identifying the port's intended purpose" }
|
||||||
{ { $link port-eof? } " - a flag indicating if the port has reached the end of file while reading" }
|
{ { $snippet "eof" } " - a flag indicating if the port has reached the end of file while reading" }
|
||||||
} } ;
|
} } ;
|
||||||
|
|
||||||
HELP: input-port
|
HELP: input-port
|
||||||
|
|
|
@ -1,46 +1,39 @@
|
||||||
! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman
|
! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
IN: io.nonblocking
|
|
||||||
USING: math kernel io sequences io.buffers io.timeouts generic
|
USING: math kernel io sequences io.buffers io.timeouts generic
|
||||||
byte-vectors system io.streams.duplex io.encodings
|
byte-vectors system io.streams.duplex io.encodings
|
||||||
io.backend continuations debugger classes byte-arrays namespaces
|
io.backend continuations debugger classes byte-arrays namespaces
|
||||||
splitting dlists assocs io.encodings.binary accessors ;
|
splitting dlists assocs io.encodings.binary accessors ;
|
||||||
|
IN: io.nonblocking
|
||||||
|
|
||||||
SYMBOL: default-buffer-size
|
SYMBOL: default-buffer-size
|
||||||
64 1024 * default-buffer-size set-global
|
64 1024 * default-buffer-size set-global
|
||||||
|
|
||||||
! Common delegate of native stream readers and writers
|
TUPLE: port handle buffer error timeout closed eof ;
|
||||||
TUPLE: port
|
|
||||||
handle
|
|
||||||
buffer
|
|
||||||
error
|
|
||||||
timeout
|
|
||||||
type eof ;
|
|
||||||
|
|
||||||
M: port timeout port-timeout ;
|
M: port timeout timeout>> ;
|
||||||
|
|
||||||
M: port set-timeout set-port-timeout ;
|
M: port set-timeout (>>timeout) ;
|
||||||
|
|
||||||
SYMBOL: closed
|
|
||||||
|
|
||||||
PREDICATE: input-port < port port-type input-port eq? ;
|
|
||||||
PREDICATE: output-port < port port-type output-port eq? ;
|
|
||||||
|
|
||||||
GENERIC: init-handle ( handle -- )
|
GENERIC: init-handle ( handle -- )
|
||||||
|
|
||||||
GENERIC: close-handle ( handle -- )
|
GENERIC: close-handle ( handle -- )
|
||||||
|
|
||||||
: <port> ( handle type -- port )
|
: <port> ( handle class -- port )
|
||||||
port construct-empty
|
construct-empty
|
||||||
swap >>type
|
swap dup init-handle >>handle ; inline
|
||||||
swap dup init-handle >>handle ;
|
|
||||||
|
|
||||||
: <buffered-port> ( handle type -- port )
|
: <buffered-port> ( handle class -- port )
|
||||||
<port>
|
<port>
|
||||||
default-buffer-size get <buffer> >>buffer ;
|
default-buffer-size get <buffer> >>buffer ; inline
|
||||||
|
|
||||||
|
TUPLE: input-port < port ;
|
||||||
|
|
||||||
: <reader> ( handle -- input-port )
|
: <reader> ( handle -- input-port )
|
||||||
input-port <buffered-port> ;
|
input-port <buffered-port> ;
|
||||||
|
|
||||||
|
TUPLE: output-port < port ;
|
||||||
|
|
||||||
: <writer> ( handle -- output-port )
|
: <writer> ( handle -- output-port )
|
||||||
output-port <buffered-port> ;
|
output-port <buffered-port> ;
|
||||||
|
|
||||||
|
@ -50,6 +43,9 @@ GENERIC: close-handle ( handle -- )
|
||||||
: pending-error ( port -- )
|
: pending-error ( port -- )
|
||||||
[ f ] change-error drop [ throw ] when* ;
|
[ f ] change-error drop [ throw ] when* ;
|
||||||
|
|
||||||
|
: check-closed ( port -- port )
|
||||||
|
dup closed>> [ "Port closed" throw ] when ;
|
||||||
|
|
||||||
HOOK: cancel-io io-backend ( port -- )
|
HOOK: cancel-io io-backend ( port -- )
|
||||||
|
|
||||||
M: object cancel-io drop ;
|
M: object cancel-io drop ;
|
||||||
|
@ -69,6 +65,7 @@ GENERIC: (wait-to-read) ( port -- )
|
||||||
[ f >>eof drop f ] r> if ; inline
|
[ f >>eof drop f ] r> if ; inline
|
||||||
|
|
||||||
M: input-port stream-read1
|
M: input-port stream-read1
|
||||||
|
check-closed
|
||||||
dup wait-to-read1 [ buffer>> buffer-pop ] unless-eof ;
|
dup wait-to-read1 [ buffer>> buffer-pop ] unless-eof ;
|
||||||
|
|
||||||
: read-step ( count port -- byte-array/f )
|
: read-step ( count port -- byte-array/f )
|
||||||
|
@ -87,6 +84,7 @@ M: input-port stream-read1
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: input-port stream-read
|
M: input-port stream-read
|
||||||
|
check-closed
|
||||||
>r 0 max >fixnum r>
|
>r 0 max >fixnum r>
|
||||||
2dup read-step dup [
|
2dup read-step dup [
|
||||||
pick over length > [
|
pick over length > [
|
||||||
|
@ -98,6 +96,7 @@ M: input-port stream-read
|
||||||
] [ 2nip ] if ;
|
] [ 2nip ] if ;
|
||||||
|
|
||||||
M: input-port stream-read-partial ( max stream -- byte-array/f )
|
M: input-port stream-read-partial ( max stream -- byte-array/f )
|
||||||
|
check-closed
|
||||||
>r 0 max >fixnum r> read-step ;
|
>r 0 max >fixnum r> read-step ;
|
||||||
|
|
||||||
: can-write? ( len buffer -- ? )
|
: can-write? ( len buffer -- ? )
|
||||||
|
@ -107,10 +106,12 @@ M: input-port stream-read-partial ( max stream -- byte-array/f )
|
||||||
tuck buffer>> can-write? [ drop ] [ stream-flush ] if ;
|
tuck buffer>> can-write? [ drop ] [ stream-flush ] if ;
|
||||||
|
|
||||||
M: output-port stream-write1
|
M: output-port stream-write1
|
||||||
|
check-closed
|
||||||
1 over wait-to-write
|
1 over wait-to-write
|
||||||
buffer>> byte>buffer ;
|
buffer>> byte>buffer ;
|
||||||
|
|
||||||
M: output-port stream-write
|
M: output-port stream-write
|
||||||
|
check-closed
|
||||||
over length over buffer>> buffer-size > [
|
over length over buffer>> buffer-size > [
|
||||||
[ buffer>> buffer-size <groups> ]
|
[ buffer>> buffer-size <groups> ]
|
||||||
[ [ stream-write ] curry ] bi
|
[ [ stream-write ] curry ] bi
|
||||||
|
@ -123,41 +124,43 @@ M: output-port stream-write
|
||||||
GENERIC: port-flush ( port -- )
|
GENERIC: port-flush ( port -- )
|
||||||
|
|
||||||
M: output-port stream-flush ( port -- )
|
M: output-port stream-flush ( port -- )
|
||||||
|
check-closed
|
||||||
[ port-flush ] [ pending-error ] bi ;
|
[ port-flush ] [ pending-error ] bi ;
|
||||||
|
|
||||||
: close-port ( port type -- )
|
GENERIC: close-port ( port -- )
|
||||||
output-port eq? [ dup port-flush ] when
|
|
||||||
|
M: output-port close-port
|
||||||
|
[ port-flush ] [ call-next-method ] bi ;
|
||||||
|
|
||||||
|
M: port close-port
|
||||||
dup cancel-io
|
dup cancel-io
|
||||||
dup handle>> close-handle
|
dup handle>> close-handle
|
||||||
[ [ buffer-free ] when* f ] change-buffer drop ;
|
[ [ buffer-free ] when* f ] change-buffer drop ;
|
||||||
|
|
||||||
M: port dispose
|
M: port dispose
|
||||||
dup type>> closed eq?
|
dup closed>> [ drop ] [ t >>closed close-port ] if ;
|
||||||
[ drop ]
|
|
||||||
[ [ closed ] change-type swap close-port ]
|
|
||||||
if ;
|
|
||||||
|
|
||||||
TUPLE: server-port addr client client-addr encoding ;
|
TUPLE: server-port < port addr client client-addr encoding ;
|
||||||
|
|
||||||
: <server-port> ( handle addr encoding -- server )
|
: <server-port> ( handle addr encoding -- server )
|
||||||
rot server-port <port>
|
rot server-port <port>
|
||||||
{ set-server-port-addr set-server-port-encoding set-delegate }
|
swap >>encoding
|
||||||
server-port construct ;
|
swap >>addr ;
|
||||||
|
|
||||||
: check-server-port ( port -- )
|
: check-server-port ( port -- port )
|
||||||
port-type server-port assert= ;
|
dup server-port? [ "Not a server port" throw ] unless ; inline
|
||||||
|
|
||||||
TUPLE: datagram-port addr packet packet-addr ;
|
TUPLE: datagram-port < port addr packet packet-addr ;
|
||||||
|
|
||||||
: <datagram-port> ( handle addr -- datagram )
|
: <datagram-port> ( handle addr -- datagram )
|
||||||
>r datagram-port <port> r>
|
swap datagram-port <port>
|
||||||
{ set-delegate set-datagram-port-addr }
|
swap >>addr ;
|
||||||
datagram-port construct ;
|
|
||||||
|
|
||||||
: check-datagram-port ( port -- )
|
: check-datagram-port ( port -- port )
|
||||||
port-type datagram-port assert= ;
|
check-closed
|
||||||
|
dup datagram-port? [ "Not a datagram port" throw ] unless ; inline
|
||||||
|
|
||||||
: check-datagram-send ( packet addrspec port -- )
|
: check-datagram-send ( packet addrspec port -- packet addrspec port )
|
||||||
dup check-datagram-port
|
check-datagram-port
|
||||||
datagram-port-addr [ class ] bi@ assert=
|
2dup addr>> [ class ] bi@ assert=
|
||||||
class byte-array assert= ;
|
pick class byte-array assert= ;
|
||||||
|
|
|
@ -12,17 +12,17 @@ SYMBOL: servers
|
||||||
|
|
||||||
LOG: accepted-connection NOTICE
|
LOG: accepted-connection NOTICE
|
||||||
|
|
||||||
: with-client ( client quot -- )
|
: with-client ( client addrspec quot -- )
|
||||||
[
|
[
|
||||||
over client-stream-addr accepted-connection
|
swap accepted-connection
|
||||||
with-stream*
|
with-stream*
|
||||||
] curry with-disposal ; inline
|
] 2curry with-disposal ; inline
|
||||||
|
|
||||||
\ with-client DEBUG add-error-logging
|
\ with-client DEBUG add-error-logging
|
||||||
|
|
||||||
: accept-loop ( server quot -- )
|
: accept-loop ( server quot -- )
|
||||||
[
|
[
|
||||||
>r accept r> [ with-client ] 2curry "Client" spawn drop
|
>r accept r> [ with-client ] 3curry "Client" spawn drop
|
||||||
] 2keep accept-loop ; inline
|
] 2keep accept-loop ; inline
|
||||||
|
|
||||||
: server-loop ( addrspec encoding quot -- )
|
: server-loop ( addrspec encoding quot -- )
|
||||||
|
|
|
@ -17,8 +17,6 @@ ARTICLE: "network-connection" "Connection-oriented networking"
|
||||||
"Connection-oriented network servers are implemented by first opening a server socket, then waiting for connections:"
|
"Connection-oriented network servers are implemented by first opening a server socket, then waiting for connections:"
|
||||||
{ $subsection <server> }
|
{ $subsection <server> }
|
||||||
{ $subsection accept }
|
{ $subsection accept }
|
||||||
"The stream returned by " { $link accept } " holds the address specifier of the remote client:"
|
|
||||||
{ $subsection client-stream-addr }
|
|
||||||
"Server sockets are closed by calling " { $link dispose } "."
|
"Server sockets are closed by calling " { $link dispose } "."
|
||||||
$nl
|
$nl
|
||||||
"Address specifiers have the following interpretation with connection-oriented networking words:"
|
"Address specifiers have the following interpretation with connection-oriented networking words:"
|
||||||
|
@ -118,10 +116,8 @@ HELP: <server>
|
||||||
{ $errors "Throws an error if the address is already in use, or if it if the system forbids access." } ;
|
{ $errors "Throws an error if the address is already in use, or if it if the system forbids access." } ;
|
||||||
|
|
||||||
HELP: accept
|
HELP: accept
|
||||||
{ $values { "server" "a handle" } { "client" "a bidirectional stream" } }
|
{ $values { "server" "a handle" } { "client" "a bidirectional stream" } { "addrspec" "an address specifier" } }
|
||||||
{ $description "Waits for a connection to a server socket created by " { $link <server> } ", and outputs a bidirectional stream when the connection has been established. The encoding of this stream is the one that was passed to the server constructor."
|
{ $description "Waits for a connection to a server socket created by " { $link <server> } ", and outputs a bidirectional stream when the connection has been established. The encoding of this stream is the one that was passed to the server constructor." }
|
||||||
$nl
|
|
||||||
"The returned client stream responds to the " { $link client-stream-addr } " word with the address of the incoming connection." }
|
|
||||||
{ $errors "Throws an error if the server socket is closed or otherwise is unavailable." } ;
|
{ $errors "Throws an error if the server socket is closed or otherwise is unavailable." } ;
|
||||||
|
|
||||||
HELP: <datagram>
|
HELP: <datagram>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007, 2008 Slava Pestov, Daniel Ehrenberg.
|
! Copyright (C) 2007, 2008 Slava Pestov, Daniel Ehrenberg.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: generic kernel io.backend namespaces continuations
|
USING: generic kernel io.backend namespaces continuations
|
||||||
sequences arrays io.encodings io.nonblocking ;
|
sequences arrays io.encodings io.nonblocking accessors ;
|
||||||
IN: io.sockets
|
IN: io.sockets
|
||||||
|
|
||||||
TUPLE: local path ;
|
TUPLE: local path ;
|
||||||
|
@ -21,20 +21,14 @@ TUPLE: inet host port ;
|
||||||
|
|
||||||
C: <inet> inet
|
C: <inet> inet
|
||||||
|
|
||||||
TUPLE: client-stream addr ;
|
HOOK: ((client)) io-backend ( addrspec -- client-in client-out )
|
||||||
|
|
||||||
: <client-stream> ( addrspec delegate -- stream )
|
GENERIC: (client) ( addrspec -- client-in client-out )
|
||||||
{ set-client-stream-addr set-delegate }
|
M: array (client) [ ((client)) 2array ] attempt-all first2 ;
|
||||||
client-stream construct ;
|
M: object (client) ((client)) ;
|
||||||
|
|
||||||
HOOK: (client) io-backend ( addrspec -- client-in client-out )
|
|
||||||
|
|
||||||
GENERIC: client* ( addrspec -- client-in client-out )
|
|
||||||
M: array client* [ (client) 2array ] attempt-all first2 ;
|
|
||||||
M: object client* (client) ;
|
|
||||||
|
|
||||||
: <client> ( addrspec encoding -- stream )
|
: <client> ( addrspec encoding -- stream )
|
||||||
>r client* r> <encoder-duplex> ;
|
>r (client) r> <encoder-duplex> ;
|
||||||
|
|
||||||
HOOK: (server) io-backend ( addrspec -- handle )
|
HOOK: (server) io-backend ( addrspec -- handle )
|
||||||
|
|
||||||
|
@ -43,10 +37,9 @@ HOOK: (server) io-backend ( addrspec -- handle )
|
||||||
|
|
||||||
HOOK: (accept) io-backend ( server -- addrspec handle )
|
HOOK: (accept) io-backend ( server -- addrspec handle )
|
||||||
|
|
||||||
: accept ( server -- client )
|
: accept ( server -- client addrspec )
|
||||||
[ (accept) dup <reader&writer> ] keep
|
[ (accept) dup <reader&writer> ] [ encoding>> ] bi
|
||||||
server-port-encoding <encoder-duplex>
|
<encoder-duplex> swap ;
|
||||||
<client-stream> ;
|
|
||||||
|
|
||||||
HOOK: <datagram> io-backend ( addrspec -- datagram )
|
HOOK: <datagram> io-backend ( addrspec -- datagram )
|
||||||
|
|
||||||
|
@ -58,7 +51,8 @@ HOOK: resolve-host io-backend ( host serv passive? -- seq )
|
||||||
|
|
||||||
HOOK: host-name io-backend ( -- string )
|
HOOK: host-name io-backend ( -- string )
|
||||||
|
|
||||||
M: inet client*
|
M: inet (client)
|
||||||
dup inet-host swap inet-port f resolve-host
|
[ host>> ] [ port>> ] bi f resolve-host
|
||||||
dup empty? [ "Host name lookup failed" throw ] when
|
[ empty? [ "Host name lookup failed" throw ] when ]
|
||||||
client* ;
|
[ (client) ]
|
||||||
|
bi ;
|
||||||
|
|
|
@ -178,7 +178,7 @@ M: write-task do-io-task
|
||||||
: (wait-to-write) ( port -- )
|
: (wait-to-write) ( port -- )
|
||||||
[ add-write-io-task ] with-port-continuation drop ;
|
[ add-write-io-task ] with-port-continuation drop ;
|
||||||
|
|
||||||
M: port port-flush ( port -- )
|
M: output-port port-flush ( port -- )
|
||||||
dup buffer>> buffer-empty? [ drop ] [ (wait-to-write) ] if ;
|
dup buffer>> buffer-empty? [ drop ] [ (wait-to-write) ] if ;
|
||||||
|
|
||||||
M: unix io-multiplex ( ms/f -- )
|
M: unix io-multiplex ( ms/f -- )
|
||||||
|
@ -190,11 +190,10 @@ M: unix (init-stdio) ( -- )
|
||||||
2 <writer> ;
|
2 <writer> ;
|
||||||
|
|
||||||
! mx io-task for embedding an fd-based mx inside another mx
|
! mx io-task for embedding an fd-based mx inside another mx
|
||||||
TUPLE: mx-port mx ;
|
TUPLE: mx-port < port mx ;
|
||||||
|
|
||||||
: <mx-port> ( mx -- port )
|
: <mx-port> ( mx -- port )
|
||||||
dup fd>> mx-port <port>
|
dup fd>> mx-port <port> swap >>mx ;
|
||||||
{ set-mx-port-mx set-delegate } mx-port construct ;
|
|
||||||
|
|
||||||
TUPLE: mx-task < io-task ;
|
TUPLE: mx-task < io-task ;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ USING: alien alien.c-types generic io kernel math namespaces
|
||||||
io.nonblocking parser threads unix sequences
|
io.nonblocking parser threads unix sequences
|
||||||
byte-arrays io.sockets io.binary io.unix.backend
|
byte-arrays io.sockets io.binary io.unix.backend
|
||||||
io.streams.duplex io.sockets.impl math.parser continuations libc
|
io.streams.duplex io.sockets.impl math.parser continuations libc
|
||||||
combinators io.backend io.files io.files.private system ;
|
combinators io.backend io.files io.files.private system accessors ;
|
||||||
IN: io.unix.sockets
|
IN: io.unix.sockets
|
||||||
|
|
||||||
: pending-init-error ( port -- )
|
: pending-init-error ( port -- )
|
||||||
|
@ -42,7 +42,7 @@ M: connect-task do-io-task
|
||||||
: wait-to-connect ( port -- )
|
: wait-to-connect ( port -- )
|
||||||
[ <connect-task> add-io-task ] with-port-continuation drop ;
|
[ <connect-task> add-io-task ] with-port-continuation drop ;
|
||||||
|
|
||||||
M: unix (client) ( addrspec -- client-in client-out )
|
M: unix ((client)) ( addrspec -- client-in client-out )
|
||||||
dup make-sockaddr/size >r >r
|
dup make-sockaddr/size >r >r
|
||||||
protocol-family SOCK_STREAM socket-fd
|
protocol-family SOCK_STREAM socket-fd
|
||||||
dup r> r> connect
|
dup r> r> connect
|
||||||
|
@ -97,11 +97,10 @@ M: unix (server) ( addrspec -- handle )
|
||||||
|
|
||||||
M: unix (accept) ( server -- addrspec handle )
|
M: unix (accept) ( server -- addrspec handle )
|
||||||
#! Wait for a client connection.
|
#! Wait for a client connection.
|
||||||
dup check-server-port
|
check-server-port
|
||||||
dup wait-to-accept
|
[ wait-to-accept ]
|
||||||
dup pending-error
|
[ pending-error ]
|
||||||
dup server-port-client-addr
|
[ [ client-addr>> ] [ client>> ] bi ] tri ;
|
||||||
swap server-port-client ;
|
|
||||||
|
|
||||||
! Datagram sockets - UDP and Unix domain
|
! Datagram sockets - UDP and Unix domain
|
||||||
M: unix <datagram>
|
M: unix <datagram>
|
||||||
|
@ -148,11 +147,10 @@ M: receive-task do-io-task
|
||||||
[ <receive-task> add-io-task ] with-port-continuation drop ;
|
[ <receive-task> add-io-task ] with-port-continuation drop ;
|
||||||
|
|
||||||
M: unix receive ( datagram -- packet addrspec )
|
M: unix receive ( datagram -- packet addrspec )
|
||||||
dup check-datagram-port
|
check-datagram-port
|
||||||
dup wait-receive
|
[ wait-receive ]
|
||||||
dup pending-error
|
[ pending-error ]
|
||||||
dup datagram-port-packet
|
[ [ packet>> ] [ packet-addr>> ] bi ] tri ;
|
||||||
swap datagram-port-packet-addr ;
|
|
||||||
|
|
||||||
: do-send ( socket data sockaddr len -- n )
|
: do-send ( socket data sockaddr len -- n )
|
||||||
>r >r dup length 0 r> r> sendto ;
|
>r >r dup length 0 r> r> sendto ;
|
||||||
|
@ -180,7 +178,7 @@ M: send-task do-io-task
|
||||||
2drop 2drop ;
|
2drop 2drop ;
|
||||||
|
|
||||||
M: unix send ( packet addrspec datagram -- )
|
M: unix send ( packet addrspec datagram -- )
|
||||||
3dup check-datagram-send
|
check-datagram-send
|
||||||
[ >r make-sockaddr/size r> wait-send ] keep
|
[ >r make-sockaddr/size r> wait-send ] keep
|
||||||
pending-error ;
|
pending-error ;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ IN: io.unix.tests
|
||||||
|
|
||||||
socket-server <local>
|
socket-server <local>
|
||||||
ascii <server> [
|
ascii <server> [
|
||||||
accept [
|
accept drop [
|
||||||
"Hello world" print flush
|
"Hello world" print flush
|
||||||
readln "XYZ" = "FOO" "BAR" ? print flush
|
readln "XYZ" = "FOO" "BAR" ? print flush
|
||||||
] with-stream
|
] with-stream
|
||||||
|
|
|
@ -122,7 +122,7 @@ TUPLE: AcceptEx-args port
|
||||||
M: winnt (accept) ( server -- addrspec handle )
|
M: winnt (accept) ( server -- addrspec handle )
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
dup check-server-port
|
check-server-port
|
||||||
\ AcceptEx-args construct-empty
|
\ AcceptEx-args construct-empty
|
||||||
[ init-accept ] keep
|
[ init-accept ] keep
|
||||||
[ ((accept)) ] keep
|
[ ((accept)) ] keep
|
||||||
|
@ -159,7 +159,7 @@ TUPLE: WSARecvFrom-args port
|
||||||
: init-WSARecvFrom ( datagram WSARecvFrom -- )
|
: init-WSARecvFrom ( datagram WSARecvFrom -- )
|
||||||
[ set-WSARecvFrom-args-port ] 2keep
|
[ set-WSARecvFrom-args-port ] 2keep
|
||||||
[
|
[
|
||||||
>r delegate port-handle delegate win32-file-handle r>
|
>r handle>> handle>> r>
|
||||||
set-WSARecvFrom-args-s*
|
set-WSARecvFrom-args-s*
|
||||||
] 2keep [
|
] 2keep [
|
||||||
>r datagram-port-addr sockaddr-type heap-size r>
|
>r datagram-port-addr sockaddr-type heap-size r>
|
||||||
|
@ -192,7 +192,7 @@ TUPLE: WSARecvFrom-args port
|
||||||
|
|
||||||
M: winnt receive ( datagram -- packet addrspec )
|
M: winnt receive ( datagram -- packet addrspec )
|
||||||
[
|
[
|
||||||
dup check-datagram-port
|
check-datagram-port
|
||||||
\ WSARecvFrom-args construct-empty
|
\ WSARecvFrom-args construct-empty
|
||||||
[ init-WSARecvFrom ] keep
|
[ init-WSARecvFrom ] keep
|
||||||
[ call-WSARecvFrom ] keep
|
[ call-WSARecvFrom ] keep
|
||||||
|
@ -244,7 +244,7 @@ USE: io.sockets
|
||||||
|
|
||||||
M: winnt send ( packet addrspec datagram -- )
|
M: winnt send ( packet addrspec datagram -- )
|
||||||
[
|
[
|
||||||
3dup check-datagram-send
|
check-datagram-send
|
||||||
\ WSASendTo-args construct-empty
|
\ WSASendTo-args construct-empty
|
||||||
[ init-WSASendTo ] keep
|
[ init-WSASendTo ] keep
|
||||||
[ call-WSASendTo ] keep
|
[ call-WSASendTo ] keep
|
||||||
|
|
|
@ -152,11 +152,10 @@ M: windows delete-directory ( path -- )
|
||||||
|
|
||||||
HOOK: WSASocket-flags io-backend ( -- DWORD )
|
HOOK: WSASocket-flags io-backend ( -- DWORD )
|
||||||
|
|
||||||
TUPLE: win32-socket ;
|
TUPLE: win32-socket < win32-file ;
|
||||||
|
|
||||||
: <win32-socket> ( handle -- win32-socket )
|
: <win32-socket> ( handle -- win32-socket )
|
||||||
f <win32-file>
|
f win32-file construct-boa ;
|
||||||
\ win32-socket construct-delegate ;
|
|
||||||
|
|
||||||
: open-socket ( family type -- socket )
|
: open-socket ( family type -- socket )
|
||||||
0 f 0 WSASocket-flags WSASocket dup socket-error ;
|
0 f 0 WSASocket-flags WSASocket dup socket-error ;
|
||||||
|
|
|
@ -22,9 +22,8 @@ IN: tools.deploy.backend
|
||||||
+stdout+ >>stderr
|
+stdout+ >>stderr
|
||||||
+closed+ >>stdin
|
+closed+ >>stdin
|
||||||
+low-priority+ >>priority
|
+low-priority+ >>priority
|
||||||
utf8 <process-stream>
|
utf8 <process-stream*>
|
||||||
dup copy-lines
|
>r copy-lines r> wait-for-process zero? [
|
||||||
process>> wait-for-process zero? [
|
|
||||||
"Deployment failed" throw
|
"Deployment failed" throw
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue