source: project/wiki/tcp-server @ 8828

Last change on this file since 8828 was 8828, checked in by Alaric Snell-Pym, 12 years ago

Wikified documentation of tcp-server

File size: 3.4 KB
Line 
1[[tags: egg]
2
3== Introduction
4
5A generic multithreaded TCP server.
6
7== Example
8
9A simple time-of-day server:
10
11<example>
12<init>(require-extension tcp-server posix)</init>
13<expr>((make-tcp-server
14  (tcp-listen 6504)
15  (lambda ()
16    (write-line (seconds->string (current-seconds))) ) )
17 #t)</expr>
18</example>
19
20== Author
21
22[[felix winkelmann|Felix Winkelmann]]
23
24== License
25
26Copyright (c) 2004, Felix L. Winkelmann
27All rights reserved.
28
29Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
30conditions are met:
31
32  Redistributions of source code must retain the above copyright notice, this list of conditions and the following
33    disclaimer.
34  Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
35    disclaimer in the documentation and/or other materials provided with the distribution.
36  Neither the name of the author nor the names of its contributors may be used to endorse or promote
37    products derived from this software without specific prior written permission.
38
39THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
40OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
41AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
42CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
43CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
46OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
47POSSIBILITY OF SUCH DAMAGE.
48
49== Requirements
50
51None
52
53== Documentation
54<procedure>(make-tcp-server LISTENER THUNK [MAXREQUESTS])</procedure>
55
56Returns a procedure that, when invoked, will start the TCP server. {{LISTENER}} should be
57a {{tcp-listener}} objects as returned by {{tcp-listen}}. For every incoming request, a
58thread will be started and {{THUNK}} (a procedure of zero arguments) will be invoked, with
59the current input- and output-ports bound so that any I/O is done from/to the client connection.
60If the optional argument {{MAXREQUESTS}} is given, then it specifies an upper limit for
61currently executing requests. The returned server procedure accepts an optional argument that
62indicates whether some diagnostic messages for incoming requests should be written to the value
63of {{(current-error-port)}}. The optional argument may be a string (which will prefix each
64diagnostic message), or just {{#t}} (which results in a default prefix).
65
66<parameter>tcp-server-prepare-hard-close-procedure</parameter>
67<parameter>tcp-server-accept-connection-procedure</parameter>
68<parameter>tcp-server-get-addresses-procedure</parameter>
69
70Parameters containing primitive socket operations. Use these to parameterize the exact
71behaviour for closing abruptly, accepting connections and getting peer addresses (for example
72to use the [[openssl]] egg in combination with the generic server).
73The default values are {{tcp-abandon-port}}, {{tcp-accept}} and {{tcp-addresses}},
74respectively.
75
76== Version History
77
78* 1.2: Added parameterized socket-primitives (Contributed by Thomas Chust)
79* 1.1: The verbosity argument of the tcp-server procedure may be a string, now.
80* 1.0
Note: See TracBrowser for help on using the repository browser.