File: server.main.html

package info (click to toggle)
yaz 3.0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,404 kB
  • ctags: 12,108
  • sloc: xml: 116,075; ansic: 52,205; sh: 9,746; tcl: 2,043; makefile: 1,141; yacc: 347
file content (117 lines) | stat: -rw-r--r-- 8,459 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<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>
    As mentioned, your <code class="function">main()</code> routine can be quite brief.
    If you want to initialize global parameters, or read global configuration
    tables, this is the place to do it. At the end of the routine, you should
    call the function
   </p><pre class="synopsis">
int statserv_main(int argc, char **argv,
                  bend_initresult *(*bend_init)(bend_initrequest *r),
                  void (*bend_close)(void *handle));
   </pre><p>
    The third and fourth arguments are pointers to handlers. Handler
    <code class="function">bend_init</code> is called whenever the server receives
    an Initialize Request, so it serves as a Z39.50 session initializer. The
    <code class="function">bend_close</code> handler is called when the session is
    closed.
   </p><p>
    <code class="function">statserv_main</code> will establish listening sockets
    according to the parameters given. When connection requests are received,
    the event handler will typically <code class="function">fork()</code> and
    create a sub-process to handle a new connection.
    Alternatively the server may be setup to create threads for each
    connection.
    If you do use global variables and forking, you should be aware, then,
    that these cannot be shared between associations, unless you explicitly
    disable forking by command line parameters. 
   </p><p>
    The server provides a mechanism for controlling some of its behavior
    without using command-line options. The function
   </p><pre class="synopsis">
    statserv_options_block *statserv_getcontrol(void);
   </pre><p>
    will return a pointer to a <code class="literal">struct statserv_options_block</code>
    describing the current default settings of the server. The structure
    contains these elements:
    
    </p><div class="variablelist"><dl><dt><span class="term">
       <code class="literal">int dynamic</code></span></dt><dd><p>
	A boolean value, which determines whether the server
	will fork on each incoming request (TRUE), or not (FALSE). Default is
	TRUE. This flag is only read by UNIX-based servers (WIN32 based servers
	doesn't fork).
       </p></dd><dt><span class="term">
       <code class="literal">int threads</code></span></dt><dd><p>
	A boolean value, which determines whether the server
	will create a thread on each incoming request (TRUE), or not (FALSE).
	Default is FALSE. This flag is only read by UNIX-based servers
	that offer POSIX Threads support.
	WIN32-based servers always operate in threaded mode.
       </p></dd><dt><span class="term">
       <code class="literal">int inetd</code></span></dt><dd><p>
	A boolean value, which determines whether the server
	will operates under a UNIX INET daemon (inetd). Default is FALSE.
       </p></dd><dt><span class="term">
       <code class="literal">char logfile[ODR_MAXNAME+1]</code></span></dt><dd><p>File for diagnostic output ("": stderr).
       </p></dd><dt><span class="term">
       <code class="literal">char apdufile[ODR_MAXNAME+1]</code></span></dt><dd><p>
	Name of file for logging incoming and outgoing APDUs
	("": don't log APDUs, "-":
	<code class="literal">stderr</code>).
       </p></dd><dt><span class="term">
      <code class="literal">char default_listen[1024]</code></span></dt><dd><p>Same form as the command-line specification of
	listener address. "": no default listener address.
	Default is to listen at "tcp:@:9999". You can only
	specify one default listener address in this fashion.
       </p></dd><dt><span class="term">
      <code class="literal">enum oid_proto default_proto;</code></span></dt><dd><p>Either <code class="literal">PROTO_Z3950</code> or
	<code class="literal">PROTO_SR</code>.
	Default is <code class="literal">PROTO_Z39_50</code>.
       </p></dd><dt><span class="term">
       <code class="literal">int idle_timeout;</code></span></dt><dd><p>Maximum session idle-time, in minutes. Zero indicates
	no (infinite) timeout. Default is 15 minutes.
       </p></dd><dt><span class="term">
       <code class="literal">int maxrecordsize;</code></span></dt><dd><p>Maximum permissible record (message) size. Default
	is 1Mb. This amount of memory will only be allocated if a
	client requests a very large amount of records in one operation
	(or a big record).
	Set it to a lower number if you are worried about resource
	consumption on your host system.
       </p></dd><dt><span class="term">
       <code class="literal">char configname[ODR_MAXNAME+1]</code></span></dt><dd><p>Passed to the backend when a new connection is received.
       </p></dd><dt><span class="term">
       <code class="literal">char setuid[ODR_MAXNAME+1]</code></span></dt><dd><p>Set user id to the user specified, after binding
	the listener addresses.
       </p></dd><dt><span class="term">
       <code class="literal">void (*bend_start)(struct statserv_options_block *p)</code>
      </span></dt><dd><p>Pointer to function which is called after the
	command line options have been parsed - but before the server
	starts listening.
	For forked UNIX servers this handler is called in the mother
	process; for threaded servers this handler is called in the
	main thread.
	The default value of this pointer is NULL in which case it
	isn't invoked by the frontend server.
	When the server operates as an NT service this handler is called
	whenever the service is started. 
       </p></dd><dt><span class="term">
       <code class="literal">void (*bend_stop)(struct statserv_options_block *p)</code>
      </span></dt><dd><p>Pointer to function which is called whenever the server
	has stopped listening for incoming connections. This function pointer
	has a default value of NULL in which case it isn't called.
	When the server operates as an NT service this handler is called
	whenever the service is stopped.
       </p></dd><dt><span class="term">
       <code class="literal">void *handle</code></span></dt><dd><p>User defined pointer (default value NULL).
	This is a per-server handle that can be used to specify "user-data".
	Do not confuse this with the session-handle as returned by bend_init.
       </p></dd></dl></div><p>
   </p><p>
    The pointer returned by <code class="literal">statserv_getcontrol</code> points to
    a static area. You are allowed to change the contents of the structure,
    but the changes will not take effect before you call
   </p><pre class="synopsis">
void statserv_setcontrol(statserv_options_block *block);
   </pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
     that you should generally update this structure before calling
     <code class="function">statserv_main()</code>.
    </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>