stop-server/stop-this-server split
parent
b4d918caa5
commit
403d5207f0
|
@ -10,7 +10,7 @@ SYMBOL: local-node
|
||||||
|
|
||||||
: handle-node-client ( -- )
|
: handle-node-client ( -- )
|
||||||
deserialize
|
deserialize
|
||||||
[ first2 get-process send ] [ stop-server ] if* ;
|
[ first2 get-process send ] [ stop-this-server ] if* ;
|
||||||
|
|
||||||
: <node-server> ( addrspec -- threaded-server )
|
: <node-server> ( addrspec -- threaded-server )
|
||||||
<threaded-server>
|
<threaded-server>
|
||||||
|
|
|
@ -179,7 +179,7 @@ http.server.dispatchers db.tuples ;
|
||||||
|
|
||||||
: add-quit-action
|
: add-quit-action
|
||||||
<action>
|
<action>
|
||||||
[ stop-server "Goodbye" "text/html" <content> ] >>display
|
[ stop-this-server "Goodbye" "text/html" <content> ] >>display
|
||||||
"quit" add-responder ;
|
"quit" add-responder ;
|
||||||
|
|
||||||
: test-db "test.db" temp-file sqlite-db ;
|
: test-db "test.db" temp-file sqlite-db ;
|
||||||
|
|
|
@ -4,8 +4,8 @@ IN: io.encodings.ascii
|
||||||
HELP: ascii
|
HELP: ascii
|
||||||
{ $class-description "ASCII encoding descriptor." } ;
|
{ $class-description "ASCII encoding descriptor." } ;
|
||||||
|
|
||||||
ARTICLE: "ascii" "ASCII encoding"
|
ARTICLE: "io.encodings.ascii" "ASCII encoding"
|
||||||
"By default, if there's a non-ASCII character in an input stream, it will be replaced with a replacement character (U+FFFD), and if a non-ASCII character is used in output, an exception is thrown."
|
"By default, if there's a non-ASCII character in an input stream, it will be replaced with a replacement character (U+FFFD), and if a non-ASCII character is used in output, an exception is thrown."
|
||||||
{ $subsection ascii } ;
|
{ $subsection ascii } ;
|
||||||
|
|
||||||
ABOUT: "ascii"
|
ABOUT: "io.encodings.ascii"
|
||||||
|
|
|
@ -58,9 +58,11 @@ ARTICLE: "io.servers.connection" "Threaded servers"
|
||||||
{ $subsection start-server }
|
{ $subsection start-server }
|
||||||
{ $subsection start-server* }
|
{ $subsection start-server* }
|
||||||
{ $subsection wait-for-server }
|
{ $subsection wait-for-server }
|
||||||
|
"Stopping the server:"
|
||||||
|
{ $subsection stop-server }
|
||||||
"From within the dynamic scope of a client handler, several words can be used to interact with the threaded server:"
|
"From within the dynamic scope of a client handler, several words can be used to interact with the threaded server:"
|
||||||
{ $subsection remote-address }
|
{ $subsection remote-address }
|
||||||
{ $subsection stop-server }
|
{ $subsection stop-this-server }
|
||||||
{ $subsection secure-port }
|
{ $subsection secure-port }
|
||||||
{ $subsection insecure-port }
|
{ $subsection insecure-port }
|
||||||
"Additionally, the " { $link local-address } " variable is set, as in " { $link with-client } "." ;
|
"Additionally, the " { $link local-address } " variable is set, as in " { $link with-client } "." ;
|
||||||
|
@ -88,7 +90,8 @@ HELP: handle-client*
|
||||||
|
|
||||||
HELP: start-server
|
HELP: start-server
|
||||||
{ $values { "threaded-server" threaded-server } }
|
{ $values { "threaded-server" threaded-server } }
|
||||||
{ $description "Starts a threaded server, returning when a client handler calls " { $link stop-server } "." } ;
|
{ $description "Starts a threaded server." }
|
||||||
|
{ $notes "Use " { $link stop-server } " or " { $link stop-this-server } " to stop the server." } ;
|
||||||
|
|
||||||
HELP: wait-for-server
|
HELP: wait-for-server
|
||||||
{ $values { "threaded-server" threaded-server } }
|
{ $values { "threaded-server" threaded-server } }
|
||||||
|
@ -96,9 +99,13 @@ HELP: wait-for-server
|
||||||
|
|
||||||
HELP: start-server*
|
HELP: start-server*
|
||||||
{ $values { "threaded-server" threaded-server } }
|
{ $values { "threaded-server" threaded-server } }
|
||||||
{ $description "Starts a threaded server, returning as soon as it is accepting connections." } ;
|
{ $description "Starts a threaded server, returning as soon as it is ready to begin accepting connections." } ;
|
||||||
|
|
||||||
HELP: stop-server
|
HELP: stop-server
|
||||||
|
{ $values { "threaded-server" threaded-server } }
|
||||||
|
{ $description "Stops a threaded server, preventing it from accepting any more connections and returning to the caller of " { $link start-server } ". All client connections which have already been opened continue to be serviced." } ;
|
||||||
|
|
||||||
|
HELP: stop-this-server
|
||||||
{ $description "Stops the current threaded server, preventing it from accepting any more connections and returning to the caller of " { $link start-server } ". All client connections which have already been opened continue to be serviced." } ;
|
{ $description "Stops the current threaded server, preventing it from accepting any more connections and returning to the caller of " { $link start-server } ". All client connections which have already been opened continue to be serviced." } ;
|
||||||
|
|
||||||
HELP: secure-port
|
HELP: secure-port
|
||||||
|
|
|
@ -33,7 +33,7 @@ concurrency.promises io.encodings.ascii io threads calendar ;
|
||||||
<threaded-server>
|
<threaded-server>
|
||||||
5 >>max-connections
|
5 >>max-connections
|
||||||
1237 >>insecure
|
1237 >>insecure
|
||||||
[ "Hello world." write stop-server ] >>handler
|
[ "Hello world." write stop-this-server ] >>handler
|
||||||
"server" set
|
"server" set
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,11 @@ PRIVATE>
|
||||||
[ wait-for-server ]
|
[ wait-for-server ]
|
||||||
bi ;
|
bi ;
|
||||||
|
|
||||||
: stop-server ( -- )
|
: stop-server ( threaded-server -- )
|
||||||
threaded-server get [ f ] change-sockets drop dispose-each ;
|
[ f ] change-sockets drop dispose-each ;
|
||||||
|
|
||||||
|
: stop-this-server ( -- )
|
||||||
|
threaded-server get stop-server ;
|
||||||
|
|
||||||
GENERIC: port ( addrspec -- n )
|
GENERIC: port ( addrspec -- n )
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ HELP: <client>
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
HELP: with-client
|
HELP: with-client
|
||||||
{ $values { "remote" "an address specifier" } { "encoding" "an encding descriptor" } { "quot" quotation } }
|
{ $values { "remote" "an address specifier" } { "encoding" "an encoding descriptor" } { "quot" quotation } }
|
||||||
{ $description "Opens a network connection and calls the quotation in a new dynamic scope with " { $link input-stream } " and " { $link output-stream } " rebound to the network streams. The local address the socket is bound to is stored in the " { $link local-address } " variable." }
|
{ $description "Opens a network connection and calls the quotation in a new dynamic scope with " { $link input-stream } " and " { $link output-stream } " rebound to the network streams. The local address the socket is bound to is stored in the " { $link local-address } " variable." }
|
||||||
{ $errors "Throws an error if the connection cannot be established." } ;
|
{ $errors "Throws an error if the connection cannot be established." } ;
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ http.server.responses http.server.static io.servers.connection ;
|
||||||
SINGLETON: quit-responder
|
SINGLETON: quit-responder
|
||||||
|
|
||||||
M: quit-responder call-responder*
|
M: quit-responder call-responder*
|
||||||
2drop stop-server "Goodbye" "text/html" <content> ;
|
2drop stop-this-server "Goodbye" "text/html" <content> ;
|
||||||
|
|
||||||
: add-quot-responder ( responder -- responder )
|
: add-quot-responder ( responder -- responder )
|
||||||
quit-responder "quit" add-responder ;
|
quit-responder "quit" add-responder ;
|
||||||
|
|
Loading…
Reference in New Issue