1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>4. Your main() Routine</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="server.html" title="Chapter 4. Generic server"><link rel="prev" href="server.backend.html" title="3. The Backend API"><link rel="next" href="server.backendfunctions.html" title="5. The Backend Functions"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4. Your main() Routine</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="server.backend.html">Prev</a> </td><th width="60%" align="center">Chapter 4. Generic server</th><td width="20%" align="right"> <a accesskey="n" href="server.backendfunctions.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="server.main"></a>4. Your main() Routine</h2></div></div></div><p>
2 As mentioned, your <code class="function">main()</code> routine can be quite brief.
3 If you want to initialize global parameters, or read global configuration
4 tables, this is the place to do it. At the end of the routine, you should
6 </p><pre class="synopsis">
7 int statserv_main(int argc, char **argv,
8 bend_initresult *(*bend_init)(bend_initrequest *r),
9 void (*bend_close)(void *handle));
11 The third and fourth arguments are pointers to handlers. Handler
12 <code class="function">bend_init</code> is called whenever the server receives
13 an Initialize Request, so it serves as a Z39.50 session initializer. The
14 <code class="function">bend_close</code> handler is called when the session is
17 <code class="function">statserv_main</code> will establish listening sockets
18 according to the parameters given. When connection requests are received,
19 the event handler will typically <code class="function">fork()</code> and
20 create a sub-process to handle a new connection.
21 Alternatively the server may be setup to create threads for each
23 If you do use global variables and forking, you should be aware, then,
24 that these cannot be shared between associations, unless you explicitly
25 disable forking by command line parameters.
27 The server provides a mechanism for controlling some of its behavior
28 without using command-line options. The function
29 </p><pre class="synopsis">
30 statserv_options_block *statserv_getcontrol(void);
32 will return a pointer to a <code class="literal">struct statserv_options_block</code>
33 describing the current default settings of the server. The structure
34 contains these elements:
36 </p><div class="variablelist"><dl><dt><span class="term">
37 <code class="literal">int dynamic</code></span></dt><dd><p>
38 A boolean value, which determines whether the server
39 will fork on each incoming request (TRUE), or not (FALSE). Default is
40 TRUE. This flag is only read by UNIX-based servers (WIN32 based servers
42 </p></dd><dt><span class="term">
43 <code class="literal">int threads</code></span></dt><dd><p>
44 A boolean value, which determines whether the server
45 will create a thread on each incoming request (TRUE), or not (FALSE).
46 Default is FALSE. This flag is only read by UNIX-based servers
47 that offer POSIX Threads support.
48 WIN32-based servers always operate in threaded mode.
49 </p></dd><dt><span class="term">
50 <code class="literal">int inetd</code></span></dt><dd><p>
51 A boolean value, which determines whether the server
52 will operates under a UNIX INET daemon (inetd). Default is FALSE.
53 </p></dd><dt><span class="term">
54 <code class="literal">char logfile[ODR_MAXNAME+1]</code></span></dt><dd><p>File for diagnostic output ("": stderr).
55 </p></dd><dt><span class="term">
56 <code class="literal">char apdufile[ODR_MAXNAME+1]</code></span></dt><dd><p>
57 Name of file for logging incoming and outgoing APDUs
58 ("": don't log APDUs, "-":
59 <code class="literal">stderr</code>).
60 </p></dd><dt><span class="term">
61 <code class="literal">char default_listen[1024]</code></span></dt><dd><p>Same form as the command-line specification of
62 listener address. "": no default listener address.
63 Default is to listen at "tcp:@:9999". You can only
64 specify one default listener address in this fashion.
65 </p></dd><dt><span class="term">
66 <code class="literal">enum oid_proto default_proto;</code></span></dt><dd><p>Either <code class="literal">PROTO_Z3950</code> or
67 <code class="literal">PROTO_SR</code>.
68 Default is <code class="literal">PROTO_Z39_50</code>.
69 </p></dd><dt><span class="term">
70 <code class="literal">int idle_timeout;</code></span></dt><dd><p>Maximum session idle-time, in minutes. Zero indicates
71 no (infinite) timeout. Default is 15 minutes.
72 </p></dd><dt><span class="term">
73 <code class="literal">int maxrecordsize;</code></span></dt><dd><p>Maximum permissible record (message) size. Default
74 is 1Mb. This amount of memory will only be allocated if a
75 client requests a very large amount of records in one operation
77 Set it to a lower number if you are worried about resource
78 consumption on your host system.
79 </p></dd><dt><span class="term">
80 <code class="literal">char configname[ODR_MAXNAME+1]</code></span></dt><dd><p>Passed to the backend when a new connection is received.
81 </p></dd><dt><span class="term">
82 <code class="literal">char setuid[ODR_MAXNAME+1]</code></span></dt><dd><p>Set user id to the user specified, after binding
83 the listener addresses.
84 </p></dd><dt><span class="term">
85 <code class="literal">void (*bend_start)(struct statserv_options_block *p)</code>
86 </span></dt><dd><p>Pointer to function which is called after the
87 command line options have been parsed - but before the server
89 For forked UNIX servers this handler is called in the mother
90 process; for threaded servers this handler is called in the
92 The default value of this pointer is NULL in which case it
93 isn't invoked by the frontend server.
94 When the server operates as an NT service this handler is called
95 whenever the service is started.
96 </p></dd><dt><span class="term">
97 <code class="literal">void (*bend_stop)(struct statserv_options_block *p)</code>
98 </span></dt><dd><p>Pointer to function which is called whenever the server
99 has stopped listening for incoming connections. This function pointer
100 has a default value of NULL in which case it isn't called.
101 When the server operates as an NT service this handler is called
102 whenever the service is stopped.
103 </p></dd><dt><span class="term">
104 <code class="literal">void *handle</code></span></dt><dd><p>User defined pointer (default value NULL).
105 This is a per-server handle that can be used to specify "user-data".
106 Do not confuse this with the session-handle as returned by bend_init.
107 </p></dd></dl></div><p>
109 The pointer returned by <code class="literal">statserv_getcontrol</code> points to
110 a static area. You are allowed to change the contents of the structure,
111 but the changes will not take effect before you call
112 </p><pre class="synopsis">
113 void statserv_setcontrol(statserv_options_block *block);
114 </pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
115 that you should generally update this structure before calling
116 <code class="function">statserv_main()</code>.
117 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="server.backend.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="server.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="server.backendfunctions.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">3. The Backend API </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5. The Backend Functions</td></tr></table></div></body></html>