stop-server/stop-this-server split

db4
Slava Pestov 2008-10-02 08:30:38 -05:00
parent b4d918caa5
commit 403d5207f0
8 changed files with 22 additions and 12 deletions

View File

@ -10,7 +10,7 @@ SYMBOL: local-node
: handle-node-client ( -- )
deserialize
[ first2 get-process send ] [ stop-server ] if* ;
[ first2 get-process send ] [ stop-this-server ] if* ;
: <node-server> ( addrspec -- threaded-server )
<threaded-server>

View File

@ -179,7 +179,7 @@ http.server.dispatchers db.tuples ;
: add-quit-action
<action>
[ stop-server "Goodbye" "text/html" <content> ] >>display
[ stop-this-server "Goodbye" "text/html" <content> ] >>display
"quit" add-responder ;
: test-db "test.db" temp-file sqlite-db ;

View File

@ -4,8 +4,8 @@ IN: io.encodings.ascii
HELP: ascii
{ $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."
{ $subsection ascii } ;
ABOUT: "ascii"
ABOUT: "io.encodings.ascii"

View File

@ -58,9 +58,11 @@ ARTICLE: "io.servers.connection" "Threaded servers"
{ $subsection start-server }
{ $subsection start-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:"
{ $subsection remote-address }
{ $subsection stop-server }
{ $subsection stop-this-server }
{ $subsection secure-port }
{ $subsection insecure-port }
"Additionally, the " { $link local-address } " variable is set, as in " { $link with-client } "." ;
@ -88,7 +90,8 @@ HELP: handle-client*
HELP: start-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
{ $values { "threaded-server" threaded-server } }
@ -96,9 +99,13 @@ HELP: wait-for-server
HELP: start-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
{ $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." } ;
HELP: secure-port

View File

@ -33,7 +33,7 @@ concurrency.promises io.encodings.ascii io threads calendar ;
<threaded-server>
5 >>max-connections
1237 >>insecure
[ "Hello world." write stop-server ] >>handler
[ "Hello world." write stop-this-server ] >>handler
"server" set
] unit-test

View File

@ -136,8 +136,11 @@ PRIVATE>
[ wait-for-server ]
bi ;
: stop-server ( -- )
threaded-server get [ f ] change-sockets drop dispose-each ;
: stop-server ( threaded-server -- )
[ f ] change-sockets drop dispose-each ;
: stop-this-server ( -- )
threaded-server get stop-server ;
GENERIC: port ( addrspec -- n )

View File

@ -104,7 +104,7 @@ HELP: <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." }
{ $errors "Throws an error if the connection cannot be established." } ;

View File

@ -66,7 +66,7 @@ http.server.responses http.server.static io.servers.connection ;
SINGLETON: quit-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 )
quit-responder "quit" add-responder ;