File: MessageServer_8h-source.html

package info (click to toggle)
passenger 2.2.11debian-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 11,576 kB
  • ctags: 28,138
  • sloc: cpp: 66,323; ruby: 9,646; ansic: 2,425; python: 141; sh: 56; makefile: 29
file content (607 lines) | stat: -rw-r--r-- 76,754 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Passenger: MessageServer.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.8 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    </ul>
  </div>
<h1>MessageServer.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> *  Phusion Passenger - http://www.modrails.com/</span>
<a name="l00003"></a>00003 <span class="comment"> *  Copyright (c) 2010 Phusion</span>
<a name="l00004"></a>00004 <span class="comment"> *</span>
<a name="l00005"></a>00005 <span class="comment"> *  "Phusion Passenger" is a trademark of Hongli Lai &amp; Ninh Bui.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> *  Permission is hereby granted, free of charge, to any person obtaining a copy</span>
<a name="l00008"></a>00008 <span class="comment"> *  of this software and associated documentation files (the "Software"), to deal</span>
<a name="l00009"></a>00009 <span class="comment"> *  in the Software without restriction, including without limitation the rights</span>
<a name="l00010"></a>00010 <span class="comment"> *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</span>
<a name="l00011"></a>00011 <span class="comment"> *  copies of the Software, and to permit persons to whom the Software is</span>
<a name="l00012"></a>00012 <span class="comment"> *  furnished to do so, subject to the following conditions:</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> *  The above copyright notice and this permission notice shall be included in</span>
<a name="l00015"></a>00015 <span class="comment"> *  all copies or substantial portions of the Software.</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</span>
<a name="l00018"></a>00018 <span class="comment"> *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00019"></a>00019 <span class="comment"> *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00020"></a>00020 <span class="comment"> *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00021"></a>00021 <span class="comment"> *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</span>
<a name="l00022"></a>00022 <span class="comment"> *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</span>
<a name="l00023"></a>00023 <span class="comment"> *  THE SOFTWARE.</span>
<a name="l00024"></a>00024 <span class="comment"> */</span>
<a name="l00025"></a>00025 <span class="preprocessor">#ifndef _PASSENGER_MESSAGE_SERVER_H_</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#define _PASSENGER_MESSAGE_SERVER_H_</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;boost/shared_ptr.hpp&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;boost/thread.hpp&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;oxt/system_calls.hpp&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;oxt/dynamic_thread_group.hpp&gt;</span>
<a name="l00035"></a>00035 
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;sys/stat.h&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;sys/un.h&gt;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &lt;unistd.h&gt;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &lt;cerrno&gt;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;cassert&gt;</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="preprocessor">#include "Account.h"</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include "AccountsDatabase.h"</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include "Constants.h"</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include "FileDescriptor.h"</span>
<a name="l00047"></a>00047 <span class="preprocessor">#include "MessageChannel.h"</span>
<a name="l00048"></a>00048 <span class="preprocessor">#include "Logging.h"</span>
<a name="l00049"></a>00049 <span class="preprocessor">#include "Exceptions.h"</span>
<a name="l00050"></a>00050 <span class="preprocessor">#include "Utils.h"</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="keyword">namespace </span>Passenger {
<a name="l00053"></a>00053 
<a name="l00054"></a>00054 <span class="keyword">using namespace </span>std;
<a name="l00055"></a>00055 <span class="keyword">using namespace </span>boost;
<a name="l00056"></a>00056 <span class="keyword">using namespace </span>oxt;
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <span class="comment">/* This source file follows the security guidelines written in Account.h. */</span>
<a name="l00060"></a>00060 <span class="comment"></span>
<a name="l00061"></a>00061 <span class="comment">/**</span>
<a name="l00062"></a>00062 <span class="comment"> * Simple pluggable request/response messaging server framework.</span>
<a name="l00063"></a>00063 <span class="comment"> *</span>
<a name="l00064"></a>00064 <span class="comment"> * MessageServer implements a server with the following properties:</span>
<a name="l00065"></a>00065 <span class="comment"> * - It listens on a Unix socket. Socket creation and destruction is automatically handled.</span>
<a name="l00066"></a>00066 <span class="comment"> *   The socket is world-writable because a username/password authentication scheme is</span>
<a name="l00067"></a>00067 <span class="comment"> *   used to enforce security.</span>
<a name="l00068"></a>00068 <span class="comment"> * - Multithreaded: 1 thread per client.</span>
<a name="l00069"></a>00069 <span class="comment"> * - Designed for simple request/response cycles. That is, a client sends a request, and</span>
<a name="l00070"></a>00070 <span class="comment"> *   the server may respond with arbitrary data. The server does not respond sporadically,</span>
<a name="l00071"></a>00071 <span class="comment"> *   i.e. it only responds after a request.</span>
<a name="l00072"></a>00072 <span class="comment"> * - Requests are discrete MessageChannel array messages, not byte streams.</span>
<a name="l00073"></a>00073 <span class="comment"> * - Connections are authenticated. Connecting clients must send a username and password,</span>
<a name="l00074"></a>00074 <span class="comment"> *   which are then checked against an accounts database. The associated account is known</span>
<a name="l00075"></a>00075 <span class="comment"> *   throughout the entire connection life time so that it's possible to implement</span>
<a name="l00076"></a>00076 <span class="comment"> *   authorization features.</span>
<a name="l00077"></a>00077 <span class="comment"> *</span>
<a name="l00078"></a>00078 <span class="comment"> * MessageServer does not process messages by itself. Instead, one registers handlers</span>
<a name="l00079"></a>00079 <span class="comment"> * which handle message processing. This framework allows one to seperate message</span>
<a name="l00080"></a>00080 <span class="comment"> * handling code by function, while allowing everything to listen on the same socket and</span>
<a name="l00081"></a>00081 <span class="comment"> * to use a common request parsing and dispatching codebase.</span>
<a name="l00082"></a>00082 <span class="comment"> *</span>
<a name="l00083"></a>00083 <span class="comment"> * A username/password authentication scheme was chosen over a file permission scheme because</span>
<a name="l00084"></a>00084 <span class="comment"> * experience has shown that the latter is inadequate. For example, the web server may</span>
<a name="l00085"></a>00085 <span class="comment"> * consist of multiple worker processes, each running as a different user. Although ACLs</span>
<a name="l00086"></a>00086 <span class="comment"> * can solve this problem as well, not every platform supports ACLs by default.</span>
<a name="l00087"></a>00087 <span class="comment"> *</span>
<a name="l00088"></a>00088 <span class="comment"> * &lt;h2&gt;Writing handlers&lt;/h2&gt;</span>
<a name="l00089"></a>00089 <span class="comment"> * Handlers must inherit from MessageServer::Handler. They may implement newClient()</span>
<a name="l00090"></a>00090 <span class="comment"> * and must implement processMessage().</span>
<a name="l00091"></a>00091 <span class="comment"> *</span>
<a name="l00092"></a>00092 <span class="comment"> * When a new client is accepted, MessageServer will call newClient() on all handlers.</span>
<a name="l00093"></a>00093 <span class="comment"> * This method accepts one argument: a common client context object. This context object</span>
<a name="l00094"></a>00094 <span class="comment"> * contains client-specific information, such as its file descriptor. It cannot be</span>
<a name="l00095"></a>00095 <span class="comment"> * extended to store more information, but it is passed to every handler anyway,</span>
<a name="l00096"></a>00096 <span class="comment"> * hence the word "common" in its name.</span>
<a name="l00097"></a>00097 <span class="comment"> * newClient() is supposed to return a handler-specific client context object for storing</span>
<a name="l00098"></a>00098 <span class="comment"> * its own information, or a null pointer if it doesn't need to store anything.</span>
<a name="l00099"></a>00099 <span class="comment"> *</span>
<a name="l00100"></a>00100 <span class="comment"> * When a client sends a request, MessageServer iterates through all handlers and calls</span>
<a name="l00101"></a>00101 <span class="comment"> * processMessage() on each one, passing it the common client context and the</span>
<a name="l00102"></a>00102 <span class="comment"> * handler-specific client context. processMessage() may return either true or false;</span>
<a name="l00103"></a>00103 <span class="comment"> * true indicates that the handler processed the message, false indicates that</span>
<a name="l00104"></a>00104 <span class="comment"> * it did not. Iteration stops at the first handler that returns true.</span>
<a name="l00105"></a>00105 <span class="comment"> * If all handlers return false, i.e. the client sent a message that no handler recognizes,</span>
<a name="l00106"></a>00106 <span class="comment"> * then MessageServer will close the connection with the client.</span>
<a name="l00107"></a>00107 <span class="comment"> *</span>
<a name="l00108"></a>00108 <span class="comment"> * Handlers do not need to be thread-safe as long as they only operate on data in the</span>
<a name="l00109"></a>00109 <span class="comment"> * context objects. MessageServer ensures that context objects are not shared with other</span>
<a name="l00110"></a>00110 <span class="comment"> * threads.</span>
<a name="l00111"></a>00111 <span class="comment"> *</span>
<a name="l00112"></a>00112 <span class="comment"> * &lt;h2&gt;Usage example&lt;/h2&gt;</span>
<a name="l00113"></a>00113 <span class="comment"> * This implements a simple ping server. Every time a "ping" request is sent, the</span>
<a name="l00114"></a>00114 <span class="comment"> * server responds with "pong" along with the number of times it had already sent</span>
<a name="l00115"></a>00115 <span class="comment"> * pong to the same client in the past.</span>
<a name="l00116"></a>00116 <span class="comment"> *</span>
<a name="l00117"></a>00117 <span class="comment"> * @code</span>
<a name="l00118"></a>00118 <span class="comment"> *   class PingHandler: public MessageServer::Handler {</span>
<a name="l00119"></a>00119 <span class="comment"> *   public:</span>
<a name="l00120"></a>00120 <span class="comment"> *       struct MyContext: public MessageServer::ClientContext {</span>
<a name="l00121"></a>00121 <span class="comment"> *           int count;</span>
<a name="l00122"></a>00122 <span class="comment"> *           </span>
<a name="l00123"></a>00123 <span class="comment"> *           MyContext() {</span>
<a name="l00124"></a>00124 <span class="comment"> *               count = 0;</span>
<a name="l00125"></a>00125 <span class="comment"> *           }</span>
<a name="l00126"></a>00126 <span class="comment"> *       };</span>
<a name="l00127"></a>00127 <span class="comment"> *       </span>
<a name="l00128"></a>00128 <span class="comment"> *       MessageServer::ClientContextPtr newClient(MessageServer::CommonClientContext &amp;commonContext) {</span>
<a name="l00129"></a>00129 <span class="comment"> *           return MessageServer::ClientContextPtr(new MyContext());</span>
<a name="l00130"></a>00130 <span class="comment"> *       }</span>
<a name="l00131"></a>00131 <span class="comment"> *       </span>
<a name="l00132"></a>00132 <span class="comment"> *       bool processMessage(MessageServer::CommonClientContext &amp;commonContext,</span>
<a name="l00133"></a>00133 <span class="comment"> *                           MessageServer::ClientContextPtr &amp;specificContext,</span>
<a name="l00134"></a>00134 <span class="comment"> *                           const vector&lt;string&gt; &amp;args)</span>
<a name="l00135"></a>00135 <span class="comment"> *       {</span>
<a name="l00136"></a>00136 <span class="comment"> *           if (args[0] == "ping") {</span>
<a name="l00137"></a>00137 <span class="comment"> *               MyContext *myContext = (MyContext *) specificContext.get();</span>
<a name="l00138"></a>00138 <span class="comment"> *               commonContext.channel.write("pong", toString(specificContext-&gt;count).c_str(), NULL);</span>
<a name="l00139"></a>00139 <span class="comment"> *               specificContext-&gt;count++;</span>
<a name="l00140"></a>00140 <span class="comment"> *               return true;</span>
<a name="l00141"></a>00141 <span class="comment"> *           } else {</span>
<a name="l00142"></a>00142 <span class="comment"> *               return false;</span>
<a name="l00143"></a>00143 <span class="comment"> *           }</span>
<a name="l00144"></a>00144 <span class="comment"> *       }</span>
<a name="l00145"></a>00145 <span class="comment"> *   };</span>
<a name="l00146"></a>00146 <span class="comment"> *   </span>
<a name="l00147"></a>00147 <span class="comment"> *   ...</span>
<a name="l00148"></a>00148 <span class="comment"> *   </span>
<a name="l00149"></a>00149 <span class="comment"> *   MessageServer server("server.sock");</span>
<a name="l00150"></a>00150 <span class="comment"> *   server.addHandler(MessageServer::HandlerPtr(new PingHandler()));</span>
<a name="l00151"></a>00151 <span class="comment"> *   server.addHandler(MessageServer::HandlerPtr(new PingHandler()));</span>
<a name="l00152"></a>00152 <span class="comment"> *   server.mainLoop();</span>
<a name="l00153"></a>00153 <span class="comment"> * @endcode</span>
<a name="l00154"></a>00154 <span class="comment"> *</span>
<a name="l00155"></a>00155 <span class="comment"> * @ingroup Support</span>
<a name="l00156"></a>00156 <span class="comment"> */</span>
<a name="l00157"></a><a class="code" href="classPassenger_1_1MessageServer.html">00157</a> <span class="keyword">class </span><a class="code" href="classPassenger_1_1MessageServer.html" title="Simple pluggable request/response messaging server framework.">MessageServer</a> {
<a name="l00158"></a>00158 <span class="keyword">public</span>:
<a name="l00159"></a>00159         <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> CLIENT_THREAD_STACK_SIZE = 64 * 1024;
<a name="l00160"></a>00160         <span class="comment"></span>
<a name="l00161"></a>00161 <span class="comment">        /** Interface for client context objects. */</span>
<a name="l00162"></a><a class="code" href="classPassenger_1_1MessageServer_1_1ClientContext.html">00162</a>         <span class="keyword">class </span><a class="code" href="classPassenger_1_1MessageServer_1_1ClientContext.html" title="Interface for client context objects.">ClientContext</a> {
<a name="l00163"></a>00163         <span class="keyword">public</span>:
<a name="l00164"></a>00164                 <span class="keyword">virtual</span> ~<a class="code" href="classPassenger_1_1MessageServer_1_1ClientContext.html" title="Interface for client context objects.">ClientContext</a>() { }
<a name="l00165"></a>00165         };
<a name="l00166"></a>00166         
<a name="l00167"></a>00167         <span class="keyword">typedef</span> shared_ptr&lt;ClientContext&gt; ClientContextPtr;
<a name="l00168"></a>00168         <span class="comment"></span>
<a name="l00169"></a>00169 <span class="comment">        /**</span>
<a name="l00170"></a>00170 <span class="comment">         * A common client context, containing client-specific information</span>
<a name="l00171"></a>00171 <span class="comment">         * used by MessageServer itself.</span>
<a name="l00172"></a>00172 <span class="comment">         */</span>
<a name="l00173"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html">00173</a>         <span class="keyword">class </span><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a>: <span class="keyword">public</span> <a class="code" href="classPassenger_1_1MessageServer_1_1ClientContext.html" title="Interface for client context objects.">ClientContext</a> {
<a name="l00174"></a>00174         <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00175"></a>00175 <span class="comment">                /** The client's socket file descriptor. */</span>
<a name="l00176"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#66485f4cbc9a23473b071924743c1c6f">00176</a>                 <a class="code" href="classPassenger_1_1FileDescriptor.html" title="Wrapper class around a file descriptor integer, for RAII behavior.">FileDescriptor</a> <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#66485f4cbc9a23473b071924743c1c6f" title="The client&amp;#39;s socket file descriptor.">fd</a>;
<a name="l00177"></a>00177                 <span class="comment"></span>
<a name="l00178"></a>00178 <span class="comment">                /** The channel that's associated with the client's socket. */</span>
<a name="l00179"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a">00179</a>                 <a class="code" href="classPassenger_1_1MessageChannel.html" title="Convenience class for I/O operations on file descriptors.">MessageChannel</a> <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>;
<a name="l00180"></a>00180                 <span class="comment"></span>
<a name="l00181"></a>00181 <span class="comment">                /** The account with which the client authenticated. */</span>
<a name="l00182"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#f12e379a0f334d695071aceadc9d1343">00182</a>                 AccountPtr <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#f12e379a0f334d695071aceadc9d1343" title="The account with which the client authenticated.">account</a>;
<a name="l00183"></a>00183                 
<a name="l00184"></a>00184                 
<a name="l00185"></a>00185                 <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a>(<a class="code" href="classPassenger_1_1FileDescriptor.html" title="Wrapper class around a file descriptor integer, for RAII behavior.">FileDescriptor</a> &amp;theFd, AccountPtr &amp;theAccount)
<a name="l00186"></a>00186                         : <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#66485f4cbc9a23473b071924743c1c6f" title="The client&amp;#39;s socket file descriptor.">fd</a>(theFd), <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>(theFd), <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#f12e379a0f334d695071aceadc9d1343" title="The account with which the client authenticated.">account</a>(theAccount)
<a name="l00187"></a>00187                 { }
<a name="l00188"></a>00188                 <span class="comment"></span>
<a name="l00189"></a>00189 <span class="comment">                /** Returns a string representation for this client context. */</span>
<a name="l00190"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#74c5f4696c7c7bbd16cd8677d856003b">00190</a>                 <span class="keywordtype">string</span> <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#74c5f4696c7c7bbd16cd8677d856003b" title="Returns a string representation for this client context.">name</a>() {
<a name="l00191"></a>00191                         <span class="keywordflow">return</span> <a class="code" href="group__Support.html#gf6fab368d70c18fdf16bf5a24f630407" title="Convert anything to a string.">toString</a>(<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>.<a class="code" href="classPassenger_1_1MessageChannel.html#0b1e25dd75783d9753f8a0d1dd42606a" title="Returns the underlying file descriptor.">filenum</a>());
<a name="l00192"></a>00192                 }
<a name="l00193"></a>00193                 <span class="comment"></span>
<a name="l00194"></a>00194 <span class="comment">                /**</span>
<a name="l00195"></a>00195 <span class="comment">                 * Checks whether this client has all of the rights in &lt;tt&gt;rights&lt;/tt&gt;. The</span>
<a name="l00196"></a>00196 <span class="comment">                 * client will be notified about the result of this check, by sending it a</span>
<a name="l00197"></a>00197 <span class="comment">                 * message.</span>
<a name="l00198"></a>00198 <span class="comment">                 *</span>
<a name="l00199"></a>00199 <span class="comment">                 * @throws SecurityException The client doesn't have one of the required rights.</span>
<a name="l00200"></a>00200 <span class="comment">                 * @throws SystemException Something went wrong while communicating with the client.</span>
<a name="l00201"></a>00201 <span class="comment">                 * @throws boost::thread_interrupted</span>
<a name="l00202"></a>00202 <span class="comment">                 */</span>
<a name="l00203"></a><a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#57a0ea308db6512e00a3526cb41be867">00203</a>                 <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#57a0ea308db6512e00a3526cb41be867" title="Checks whether this client has all of the rights in rights.">requireRights</a>(Account::Rights rights) {
<a name="l00204"></a>00204                         <span class="keywordflow">if</span> (!<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#f12e379a0f334d695071aceadc9d1343" title="The account with which the client authenticated.">account</a>-&gt;hasRights(rights)) {
<a name="l00205"></a>00205                                 P_TRACE(2, <span class="stringliteral">"Security error: insufficient rights to execute this command."</span>);
<a name="l00206"></a>00206                                 <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"SecurityException"</span>, <span class="stringliteral">"Insufficient rights to execute this command."</span>, NULL);
<a name="l00207"></a>00207                                 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SecurityException.html" title="Represents some kind of security error.">SecurityException</a>(<span class="stringliteral">"Insufficient rights to execute this command."</span>);
<a name="l00208"></a>00208                         } <span class="keywordflow">else</span> {
<a name="l00209"></a>00209                                 <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"Passed security"</span>, NULL);
<a name="l00210"></a>00210                         }
<a name="l00211"></a>00211                 }
<a name="l00212"></a>00212         };
<a name="l00213"></a>00213         <span class="comment"></span>
<a name="l00214"></a>00214 <span class="comment">        /**</span>
<a name="l00215"></a>00215 <span class="comment">         * An abstract message handler class.</span>
<a name="l00216"></a>00216 <span class="comment">         *</span>
<a name="l00217"></a>00217 <span class="comment">         * The methods defined in this class are allowed to throw arbitrary exceptions.</span>
<a name="l00218"></a>00218 <span class="comment">         * Such exceptions are caught and logged, after which the connection to the</span>
<a name="l00219"></a>00219 <span class="comment">         * client is closed.</span>
<a name="l00220"></a>00220 <span class="comment">         */</span>
<a name="l00221"></a><a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html">00221</a>         <span class="keyword">class </span><a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html" title="An abstract message handler class.">Handler</a> {
<a name="l00222"></a>00222         <span class="keyword">public</span>:
<a name="l00223"></a>00223                 <span class="keyword">virtual</span> ~<a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html" title="An abstract message handler class.">Handler</a>() { }
<a name="l00224"></a>00224                 <span class="comment"></span>
<a name="l00225"></a>00225 <span class="comment">                /**</span>
<a name="l00226"></a>00226 <span class="comment">                 * Called when a new client has connected to the MessageServer.</span>
<a name="l00227"></a>00227 <span class="comment">                 *</span>
<a name="l00228"></a>00228 <span class="comment">                 * This method is called after the client has authenticated itself.</span>
<a name="l00229"></a>00229 <span class="comment">                 *</span>
<a name="l00230"></a>00230 <span class="comment">                 * @param context Contains common client-specific information.</span>
<a name="l00231"></a>00231 <span class="comment">                 * @return A client context object for storing handler-specific client</span>
<a name="l00232"></a>00232 <span class="comment">                 *         information, or null. The default implementation returns null.</span>
<a name="l00233"></a>00233 <span class="comment">                 */</span>
<a name="l00234"></a><a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html#3dcae8f3416eba769b4971083eeaee8d">00234</a>                 <span class="keyword">virtual</span> ClientContextPtr <a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html#3dcae8f3416eba769b4971083eeaee8d" title="Called when a new client has connected to the MessageServer.">newClient</a>(<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a> &amp;context) {
<a name="l00235"></a>00235                         <span class="keywordflow">return</span> ClientContextPtr();
<a name="l00236"></a>00236                 }
<a name="l00237"></a>00237                 <span class="comment"></span>
<a name="l00238"></a>00238 <span class="comment">                /**</span>
<a name="l00239"></a>00239 <span class="comment">                 * Called when a client has disconnected from the MessageServer. The</span>
<a name="l00240"></a>00240 <span class="comment">                 * default implementation does nothing.</span>
<a name="l00241"></a>00241 <span class="comment">                 *</span>
<a name="l00242"></a>00242 <span class="comment">                 * This method is called even if processMessage() throws an exception.</span>
<a name="l00243"></a>00243 <span class="comment">                 * It is however not called if newClient() throws an exception.</span>
<a name="l00244"></a>00244 <span class="comment">                 *</span>
<a name="l00245"></a>00245 <span class="comment">                 * @param commonContext Contains common client-specific information.</span>
<a name="l00246"></a>00246 <span class="comment">                 * @param handlerSpecificContext The client context object as was returned</span>
<a name="l00247"></a>00247 <span class="comment">                 *     earlier by newClient().</span>
<a name="l00248"></a>00248 <span class="comment">                 */</span>
<a name="l00249"></a><a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html#63bf8b0539e86e862cfc2defe6dc9300">00249</a>                 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html#63bf8b0539e86e862cfc2defe6dc9300" title="Called when a client has disconnected from the MessageServer.">clientDisconnected</a>(<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">MessageServer::CommonClientContext</a> &amp;context,
<a name="l00250"></a>00250                                                 MessageServer::ClientContextPtr &amp;handlerSpecificContext)
<a name="l00251"></a>00251                 { }
<a name="l00252"></a>00252                 <span class="comment"></span>
<a name="l00253"></a>00253 <span class="comment">                /**</span>
<a name="l00254"></a>00254 <span class="comment">                 * Called then a client has sent a request message.</span>
<a name="l00255"></a>00255 <span class="comment">                 *</span>
<a name="l00256"></a>00256 <span class="comment">                 * This method is called after newClient() is called.</span>
<a name="l00257"></a>00257 <span class="comment">                 *</span>
<a name="l00258"></a>00258 <span class="comment">                 * @param commonContext Contains common client-specific information.</span>
<a name="l00259"></a>00259 <span class="comment">                 * @param handlerSpecificContext The client context object as was returned</span>
<a name="l00260"></a>00260 <span class="comment">                 *     earlier by newClient().</span>
<a name="l00261"></a>00261 <span class="comment">                 * @param args The request message's contents.</span>
<a name="l00262"></a>00262 <span class="comment">                 * @return Whether this handler has processed the message. Return false</span>
<a name="l00263"></a>00263 <span class="comment">                 *         if the message is unrecognized.</span>
<a name="l00264"></a>00264 <span class="comment">                 */</span>
<a name="l00265"></a>00265                 <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classPassenger_1_1MessageServer_1_1Handler.html#4bc6162024c6e2bc450f8772897a628d" title="Called then a client has sent a request message.">processMessage</a>(<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a> &amp;commonContext,
<a name="l00266"></a>00266                                             ClientContextPtr &amp;handlerSpecificContext,
<a name="l00267"></a>00267                                             <span class="keyword">const</span> vector&lt;string&gt; &amp;args) = 0;
<a name="l00268"></a>00268         };
<a name="l00269"></a>00269         
<a name="l00270"></a>00270         <span class="keyword">typedef</span> shared_ptr&lt;Handler&gt; HandlerPtr;
<a name="l00271"></a>00271         
<a name="l00272"></a>00272 <span class="keyword">protected</span>:<span class="comment"></span>
<a name="l00273"></a>00273 <span class="comment">        /** The filename of the server socket on which this MessageServer is listening. */</span>
<a name="l00274"></a><a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3">00274</a>         <span class="keywordtype">string</span> <a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>;
<a name="l00275"></a>00275         <span class="comment"></span>
<a name="l00276"></a>00276 <span class="comment">        /** An accounts database, used for authenticating clients. */</span>
<a name="l00277"></a><a class="code" href="classPassenger_1_1MessageServer.html#4705130bf6626dd2201e7d73ead57b93">00277</a>         AccountsDatabasePtr <a class="code" href="classPassenger_1_1MessageServer.html#4705130bf6626dd2201e7d73ead57b93" title="An accounts database, used for authenticating clients.">accountsDatabase</a>;
<a name="l00278"></a>00278         <span class="comment"></span>
<a name="l00279"></a>00279 <span class="comment">        /** The registered message handlers. */</span>
<a name="l00280"></a><a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a">00280</a>         vector&lt;HandlerPtr&gt; <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>;
<a name="l00281"></a>00281         <span class="comment"></span>
<a name="l00282"></a>00282 <span class="comment">        /** The maximum number of milliseconds that client may spend on logging in.</span>
<a name="l00283"></a>00283 <span class="comment">         * Clients that take longer are disconnected.</span>
<a name="l00284"></a>00284 <span class="comment">         *</span>
<a name="l00285"></a>00285 <span class="comment">         * @invariant loginTimeout != 0</span>
<a name="l00286"></a>00286 <span class="comment">         */</span>
<a name="l00287"></a><a class="code" href="classPassenger_1_1MessageServer.html#bf5075add15c5f32a60039bdcbe98926">00287</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> <a class="code" href="classPassenger_1_1MessageServer.html#bf5075add15c5f32a60039bdcbe98926" title="The maximum number of milliseconds that client may spend on logging in.">loginTimeout</a>;
<a name="l00288"></a>00288         <span class="comment"></span>
<a name="l00289"></a>00289 <span class="comment">        /** The client threads. */</span>
<a name="l00290"></a><a class="code" href="classPassenger_1_1MessageServer.html#48ccf2c09c2c8b5dcfe3a0585dba67cf">00290</a>         dynamic_thread_group <a class="code" href="classPassenger_1_1MessageServer.html#48ccf2c09c2c8b5dcfe3a0585dba67cf" title="The client threads.">threadGroup</a>;
<a name="l00291"></a>00291         <span class="comment"></span>
<a name="l00292"></a>00292 <span class="comment">        /** The server socket's file descriptor.</span>
<a name="l00293"></a>00293 <span class="comment">         * @invariant serverFd &gt;= 0</span>
<a name="l00294"></a>00294 <span class="comment">         */</span>
<a name="l00295"></a><a class="code" href="classPassenger_1_1MessageServer.html#ef3c642484fbbbfc46b7768c53a5c0d4">00295</a>         <span class="keywordtype">int</span> <a class="code" href="classPassenger_1_1MessageServer.html#ef3c642484fbbbfc46b7768c53a5c0d4" title="The server socket&amp;#39;s file descriptor.">serverFd</a>;
<a name="l00296"></a>00296         
<a name="l00297"></a>00297         <span class="comment"></span>
<a name="l00298"></a>00298 <span class="comment">        /** Calls clientDisconnected() on all handlers when destroyed. */</span>
<a name="l00299"></a><a class="code" href="structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html">00299</a>         <span class="keyword">struct </span><a class="code" href="structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html" title="Calls clientDisconnected() on all handlers when destroyed.">DisconnectEventBroadcastGuard</a> {
<a name="l00300"></a>00300                 vector&lt;HandlerPtr&gt; &amp;handlers;
<a name="l00301"></a>00301                 <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a> &amp;commonContext;
<a name="l00302"></a>00302                 vector&lt;ClientContextPtr&gt; &amp;handlerSpecificContexts;
<a name="l00303"></a>00303                 
<a name="l00304"></a>00304                 <a class="code" href="structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html" title="Calls clientDisconnected() on all handlers when destroyed.">DisconnectEventBroadcastGuard</a>(vector&lt;HandlerPtr&gt; &amp;_handlers,
<a name="l00305"></a>00305                                               <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a> &amp;_commonContext,
<a name="l00306"></a>00306                                               vector&lt;ClientContextPtr&gt; &amp;_handlerSpecificContexts)
<a name="l00307"></a>00307                 : handlers(_handlers),
<a name="l00308"></a>00308                   commonContext(_commonContext),
<a name="l00309"></a>00309                   handlerSpecificContexts(_handlerSpecificContexts)
<a name="l00310"></a>00310                 { }
<a name="l00311"></a>00311                 
<a name="l00312"></a>00312                 ~<a class="code" href="structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html" title="Calls clientDisconnected() on all handlers when destroyed.">DisconnectEventBroadcastGuard</a>() {
<a name="l00313"></a>00313                         vector&lt;HandlerPtr&gt;::iterator handler_iter;
<a name="l00314"></a>00314                         vector&lt;ClientContextPtr&gt;::iterator context_iter;
<a name="l00315"></a>00315 
<a name="l00316"></a>00316                         <span class="keywordflow">for</span> (handler_iter = handlers.begin(), context_iter = handlerSpecificContexts.begin();
<a name="l00317"></a>00317                              handler_iter != handlers.end();
<a name="l00318"></a>00318                              handler_iter++, context_iter++) {
<a name="l00319"></a>00319                                 (*handler_iter)-&gt;clientDisconnected(commonContext, *context_iter);
<a name="l00320"></a>00320                         }
<a name="l00321"></a>00321                 }
<a name="l00322"></a>00322         };
<a name="l00323"></a>00323         
<a name="l00324"></a>00324         <span class="comment"></span>
<a name="l00325"></a>00325 <span class="comment">        /**</span>
<a name="l00326"></a>00326 <span class="comment">         * Create a server socket and set it up for listening. This socket will</span>
<a name="l00327"></a>00327 <span class="comment">         * be world-writable.</span>
<a name="l00328"></a>00328 <span class="comment">         *</span>
<a name="l00329"></a>00329 <span class="comment">         * @throws RuntimeException</span>
<a name="l00330"></a>00330 <span class="comment">         * @throws SystemException</span>
<a name="l00331"></a>00331 <span class="comment">         * @throws boost::thread_interrupted</span>
<a name="l00332"></a>00332 <span class="comment">         */</span>
<a name="l00333"></a><a class="code" href="classPassenger_1_1MessageServer.html#86f9ec99fe5dbed5c04d4b9e8f170995">00333</a>         <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer.html#86f9ec99fe5dbed5c04d4b9e8f170995" title="Create a server socket and set it up for listening.">startListening</a>() {
<a name="l00334"></a>00334                 TRACE_POINT();
<a name="l00335"></a>00335                 <span class="keywordtype">int</span> ret;
<a name="l00336"></a>00336                 
<a name="l00337"></a>00337                 <a class="code" href="classPassenger_1_1MessageServer.html#ef3c642484fbbbfc46b7768c53a5c0d4" title="The server socket&amp;#39;s file descriptor.">serverFd</a> = <a class="code" href="group__Support.html#g5d3b342a34d81e7506744e90ee2f9b8b" title="Create a new Unix server socket which is bounded to filename.">createUnixServer</a>(<a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>.c_str());
<a name="l00338"></a>00338                 <span class="keywordflow">do</span> {
<a name="l00339"></a>00339                         ret = chmod(<a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>.c_str(),
<a name="l00340"></a>00340                                 S_ISVTX |
<a name="l00341"></a>00341                                 S_IRUSR | S_IWUSR | S_IXUSR |
<a name="l00342"></a>00342                                 S_IRGRP | S_IWGRP | S_IXGRP |
<a name="l00343"></a>00343                                 S_IROTH | S_IWOTH | S_IXOTH);
<a name="l00344"></a>00344                 } <span class="keywordflow">while</span> (ret == -1 &amp;&amp; errno == EINTR);
<a name="l00345"></a>00345         }
<a name="l00346"></a>00346         <span class="comment"></span>
<a name="l00347"></a>00347 <span class="comment">        /**</span>
<a name="l00348"></a>00348 <span class="comment">         * Authenticate the given client and returns its account information.</span>
<a name="l00349"></a>00349 <span class="comment">         *</span>
<a name="l00350"></a>00350 <span class="comment">         * @return A smart pointer to an Account object, or NULL if authentication failed.</span>
<a name="l00351"></a>00351 <span class="comment">         */</span>
<a name="l00352"></a><a class="code" href="classPassenger_1_1MessageServer.html#6687fdc90ef1c361a69c0fdcde38bb42">00352</a>         AccountPtr <a class="code" href="classPassenger_1_1MessageServer.html#6687fdc90ef1c361a69c0fdcde38bb42" title="Authenticate the given client and returns its account information.">authenticate</a>(<a class="code" href="classPassenger_1_1FileDescriptor.html" title="Wrapper class around a file descriptor integer, for RAII behavior.">FileDescriptor</a> &amp;client) {
<a name="l00353"></a>00353                 <a class="code" href="classPassenger_1_1MessageChannel.html" title="Convenience class for I/O operations on file descriptors.">MessageChannel</a> channel(client);
<a name="l00354"></a>00354                 <span class="keywordtype">string</span> username, password;
<a name="l00355"></a>00355                 <a class="code" href="classPassenger_1_1MemZeroGuard.html" title="Fills the given memory space or string with zeroes when a MemoryZeroGuard object...">MemZeroGuard</a> passwordGuard(password);
<a name="l00356"></a>00356                 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> timeout = <a class="code" href="classPassenger_1_1MessageServer.html#bf5075add15c5f32a60039bdcbe98926" title="The maximum number of milliseconds that client may spend on logging in.">loginTimeout</a>;
<a name="l00357"></a>00357                 
<a name="l00358"></a>00358                 <span class="keywordflow">try</span> {
<a name="l00359"></a>00359                         <span class="keywordflow">try</span> {
<a name="l00360"></a>00360                                 <span class="keywordflow">if</span> (!channel.<a class="code" href="classPassenger_1_1MessageChannel.html#1f3cf672b566166ed920c2bba4d19604" title="Read a scalar message from the underlying file descriptor.">readScalar</a>(username, 50, &amp;timeout)) {
<a name="l00361"></a>00361                                         <span class="keywordflow">return</span> AccountPtr();
<a name="l00362"></a>00362                                 }
<a name="l00363"></a>00363                         } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classPassenger_1_1SecurityException.html" title="Represents some kind of security error.">SecurityException</a> &amp;) {
<a name="l00364"></a>00364                                 channel.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"The supplied username is too long."</span>, NULL);
<a name="l00365"></a>00365                                 <span class="keywordflow">return</span> AccountPtr();
<a name="l00366"></a>00366                         }
<a name="l00367"></a>00367                         
<a name="l00368"></a>00368                         <span class="keywordflow">try</span> {
<a name="l00369"></a>00369                                 <span class="keywordflow">if</span> (!channel.<a class="code" href="classPassenger_1_1MessageChannel.html#1f3cf672b566166ed920c2bba4d19604" title="Read a scalar message from the underlying file descriptor.">readScalar</a>(password, MESSAGE_SERVER_MAX_PASSWORD_SIZE, &amp;timeout)) {
<a name="l00370"></a>00370                                         <span class="keywordflow">return</span> AccountPtr();
<a name="l00371"></a>00371                                 }
<a name="l00372"></a>00372                         } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classPassenger_1_1SecurityException.html" title="Represents some kind of security error.">SecurityException</a> &amp;) {
<a name="l00373"></a>00373                                 channel.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"The supplied password is too long."</span>, NULL);
<a name="l00374"></a>00374                                 <span class="keywordflow">return</span> AccountPtr();
<a name="l00375"></a>00375                         }
<a name="l00376"></a>00376                         
<a name="l00377"></a>00377                         AccountPtr account = <a class="code" href="classPassenger_1_1MessageServer.html#4705130bf6626dd2201e7d73ead57b93" title="An accounts database, used for authenticating clients.">accountsDatabase</a>-&gt;authenticate(username, password);
<a name="l00378"></a>00378                         passwordGuard.<a class="code" href="classPassenger_1_1MemZeroGuard.html#fbefb3b41c341bcaeaa9c23f698df15c" title="Zero the data immediately.">zeroNow</a>();
<a name="l00379"></a>00379                         <span class="keywordflow">if</span> (account == NULL) {
<a name="l00380"></a>00380                                 channel.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"Invalid username or password."</span>, NULL);
<a name="l00381"></a>00381                                 <span class="keywordflow">return</span> AccountPtr();
<a name="l00382"></a>00382                         } <span class="keywordflow">else</span> {
<a name="l00383"></a>00383                                 channel.<a class="code" href="classPassenger_1_1MessageChannel.html#150f68bc47e060dcc6ca35bee047914d" title="Send an array message, which consists of the given elements, over the underlying...">write</a>(<span class="stringliteral">"ok"</span>, NULL);
<a name="l00384"></a>00384                                 <span class="keywordflow">return</span> account;
<a name="l00385"></a>00385                         }
<a name="l00386"></a>00386                 } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a> &amp;) {
<a name="l00387"></a>00387                         <span class="keywordflow">return</span> AccountPtr();
<a name="l00388"></a>00388                 } <span class="keywordflow">catch</span> (<span class="keyword">const</span> <a class="code" href="classPassenger_1_1TimeoutException.html" title="An exception indicating that some timeout expired.">TimeoutException</a> &amp;) {
<a name="l00389"></a>00389                         <span class="keywordflow">return</span> AccountPtr();
<a name="l00390"></a>00390                 }
<a name="l00391"></a>00391         }
<a name="l00392"></a>00392         
<a name="l00393"></a>00393         <span class="keywordtype">void</span> broadcastNewClientEvent(CommonClientContext &amp;context,
<a name="l00394"></a>00394                                      vector&lt;ClientContextPtr&gt; &amp;handlerSpecificContexts) {
<a name="l00395"></a>00395                 vector&lt;HandlerPtr&gt;::iterator it;
<a name="l00396"></a>00396                 
<a name="l00397"></a>00397                 <span class="keywordflow">for</span> (it = <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>.begin(); it != <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>.end(); it++) {
<a name="l00398"></a>00398                         handlerSpecificContexts.push_back((*it)-&gt;newClient(context));
<a name="l00399"></a>00399                 }
<a name="l00400"></a>00400         }
<a name="l00401"></a>00401         
<a name="l00402"></a>00402         <span class="keywordtype">bool</span> processMessage(CommonClientContext &amp;commonContext,
<a name="l00403"></a>00403                             vector&lt;ClientContextPtr&gt; &amp;handlerSpecificContexts,
<a name="l00404"></a>00404                             <span class="keyword">const</span> vector&lt;string&gt; &amp;args) {
<a name="l00405"></a>00405                 vector&lt;HandlerPtr&gt;::iterator handler_iter;
<a name="l00406"></a>00406                 vector&lt;ClientContextPtr&gt;::iterator context_iter;
<a name="l00407"></a>00407                 
<a name="l00408"></a>00408                 <span class="keywordflow">for</span> (handler_iter = <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>.begin(), context_iter = handlerSpecificContexts.begin();
<a name="l00409"></a>00409                      handler_iter != <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>.end();
<a name="l00410"></a>00410                      handler_iter++, context_iter++) {
<a name="l00411"></a>00411                         <span class="keywordflow">if</span> ((*handler_iter)-&gt;processMessage(commonContext, *context_iter, args)) {
<a name="l00412"></a>00412                                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00413"></a>00413                         }
<a name="l00414"></a>00414                 }
<a name="l00415"></a>00415                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00416"></a>00416         }
<a name="l00417"></a>00417         
<a name="l00418"></a>00418         <span class="keywordtype">void</span> processUnknownMessage(CommonClientContext &amp;commonContext, <span class="keyword">const</span> vector&lt;string&gt; &amp;args) {
<a name="l00419"></a>00419                 TRACE_POINT();
<a name="l00420"></a>00420                 <span class="keywordtype">string</span> name;
<a name="l00421"></a>00421                 <span class="keywordflow">if</span> (args.empty()) {
<a name="l00422"></a>00422                         name = <span class="stringliteral">"(null)"</span>;
<a name="l00423"></a>00423                 } <span class="keywordflow">else</span> {
<a name="l00424"></a>00424                         name = args[0];
<a name="l00425"></a>00425                 }
<a name="l00426"></a>00426                 P_TRACE(2, <span class="stringliteral">"A MessageServer client sent an invalid command: "</span>
<a name="l00427"></a>00427                         &lt;&lt; name &lt;&lt; <span class="stringliteral">" ("</span> &lt;&lt; args.size() &lt;&lt; <span class="stringliteral">" elements)"</span>);
<a name="l00428"></a>00428         }
<a name="l00429"></a>00429         <span class="comment"></span>
<a name="l00430"></a>00430 <span class="comment">        /**</span>
<a name="l00431"></a>00431 <span class="comment">         * The main function for a thread which handles a client.</span>
<a name="l00432"></a>00432 <span class="comment">         */</span>
<a name="l00433"></a><a class="code" href="classPassenger_1_1MessageServer.html#c7d708f90b3a1b1ae5e7b215c688c95e">00433</a>         <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer.html#c7d708f90b3a1b1ae5e7b215c688c95e" title="The main function for a thread which handles a client.">clientHandlingMainLoop</a>(<a class="code" href="classPassenger_1_1FileDescriptor.html" title="Wrapper class around a file descriptor integer, for RAII behavior.">FileDescriptor</a> &amp;client) {
<a name="l00434"></a>00434                 TRACE_POINT();
<a name="l00435"></a>00435                 vector&lt;string&gt; args;
<a name="l00436"></a>00436                 
<a name="l00437"></a>00437                 P_TRACE(4, <span class="stringliteral">"MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt; <span class="stringliteral">" started."</span>);
<a name="l00438"></a>00438                 
<a name="l00439"></a>00439                 <span class="keywordflow">try</span> {
<a name="l00440"></a>00440                         AccountPtr account(<a class="code" href="classPassenger_1_1MessageServer.html#6687fdc90ef1c361a69c0fdcde38bb42" title="Authenticate the given client and returns its account information.">authenticate</a>(client));
<a name="l00441"></a>00441                         <span class="keywordflow">if</span> (account == NULL) {
<a name="l00442"></a>00442                                 P_TRACE(4, <span class="stringliteral">"MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt; <span class="stringliteral">" exited."</span>);
<a name="l00443"></a>00443                                 <span class="keywordflow">return</span>;
<a name="l00444"></a>00444                         }
<a name="l00445"></a>00445                         
<a name="l00446"></a>00446                         <a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html" title="A common client context, containing client-specific information used by MessageServer...">CommonClientContext</a> commonContext(client, account);
<a name="l00447"></a>00447                         vector&lt;ClientContextPtr&gt; handlerSpecificContexts;
<a name="l00448"></a>00448                         broadcastNewClientEvent(commonContext, handlerSpecificContexts);
<a name="l00449"></a>00449                         <a class="code" href="structPassenger_1_1MessageServer_1_1DisconnectEventBroadcastGuard.html" title="Calls clientDisconnected() on all handlers when destroyed.">DisconnectEventBroadcastGuard</a> dguard(<a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>, commonContext, handlerSpecificContexts);
<a name="l00450"></a>00450                         
<a name="l00451"></a>00451                         <span class="keywordflow">while</span> (!this_thread::interruption_requested()) {
<a name="l00452"></a>00452                                 UPDATE_TRACE_POINT();
<a name="l00453"></a>00453                                 <span class="keywordflow">if</span> (!commonContext.<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#1401aab009ce4f77c4e3aba1990c8f4a" title="The channel that&amp;#39;s associated with the client&amp;#39;s socket.">channel</a>.<a class="code" href="classPassenger_1_1MessageChannel.html#129659b60d1a663337873d2af944431e" title="Read an array message from the underlying file descriptor.">read</a>(args)) {
<a name="l00454"></a>00454                                         <span class="comment">// Client closed connection.</span>
<a name="l00455"></a>00455                                         <span class="keywordflow">break</span>;
<a name="l00456"></a>00456                                 }
<a name="l00457"></a>00457                                 
<a name="l00458"></a>00458                                 P_TRACE(4, <span class="stringliteral">"MessageServer client "</span> &lt;&lt; commonContext.<a class="code" href="classPassenger_1_1MessageServer_1_1CommonClientContext.html#74c5f4696c7c7bbd16cd8677d856003b" title="Returns a string representation for this client context.">name</a>() &lt;&lt;
<a name="l00459"></a>00459                                         <span class="stringliteral">": received message: "</span> &lt;&lt; <a class="code" href="group__Support.html#gf6fab368d70c18fdf16bf5a24f630407" title="Convert anything to a string.">toString</a>(args));
<a name="l00460"></a>00460                                 
<a name="l00461"></a>00461                                 UPDATE_TRACE_POINT();
<a name="l00462"></a>00462                                 <span class="keywordflow">if</span> (!processMessage(commonContext, handlerSpecificContexts, args)) {
<a name="l00463"></a>00463                                         processUnknownMessage(commonContext, args);
<a name="l00464"></a>00464                                         <span class="keywordflow">break</span>;
<a name="l00465"></a>00465                                 }
<a name="l00466"></a>00466                                 args.clear();
<a name="l00467"></a>00467                         }
<a name="l00468"></a>00468                         
<a name="l00469"></a>00469                         client.<a class="code" href="classPassenger_1_1FileDescriptor.html#d7c1a99531181878cbab74a7400c5432" title="Close the underlying file descriptor.">close</a>();
<a name="l00470"></a>00470                         P_TRACE(4, <span class="stringliteral">"MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt; <span class="stringliteral">" exited."</span>);
<a name="l00471"></a>00471                 } <span class="keywordflow">catch</span> (<span class="keyword">const</span> boost::thread_interrupted &amp;) {
<a name="l00472"></a>00472                         P_TRACE(2, <span class="stringliteral">"MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt; <span class="stringliteral">" interrupted."</span>);
<a name="l00473"></a>00473                 } <span class="keywordflow">catch</span> (<span class="keyword">const</span> tracable_exception &amp;e) {
<a name="l00474"></a>00474                         P_TRACE(2, <span class="stringliteral">"An error occurred in a MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt; <span class="stringliteral">":\n"</span>
<a name="l00475"></a>00475                                 &lt;&lt; <span class="stringliteral">"   message: "</span> &lt;&lt; <a class="code" href="group__Support.html#gf6fab368d70c18fdf16bf5a24f630407" title="Convert anything to a string.">toString</a>(args) &lt;&lt; <span class="stringliteral">"\n"</span>
<a name="l00476"></a>00476                                 &lt;&lt; <span class="stringliteral">"   exception: "</span> &lt;&lt; e.what() &lt;&lt; <span class="stringliteral">"\n"</span>
<a name="l00477"></a>00477                                 &lt;&lt; <span class="stringliteral">"   backtrace:\n"</span> &lt;&lt; e.backtrace());
<a name="l00478"></a>00478                 } <span class="keywordflow">catch</span> (<span class="keyword">const</span> std::exception &amp;e) {
<a name="l00479"></a>00479                         P_TRACE(2, <span class="stringliteral">"An error occurred in a MessageServer client thread "</span> &lt;&lt; (<span class="keywordtype">int</span>) client &lt;&lt;<span class="stringliteral">":\n"</span>
<a name="l00480"></a>00480                                 &lt;&lt; <span class="stringliteral">"   message: "</span> &lt;&lt; <a class="code" href="group__Support.html#gf6fab368d70c18fdf16bf5a24f630407" title="Convert anything to a string.">toString</a>(args) &lt;&lt; <span class="stringliteral">"\n"</span>
<a name="l00481"></a>00481                                 &lt;&lt; <span class="stringliteral">"   exception: "</span> &lt;&lt; e.what() &lt;&lt; <span class="stringliteral">"\n"</span>
<a name="l00482"></a>00482                                 &lt;&lt; <span class="stringliteral">"   backtrace: not available"</span>);
<a name="l00483"></a>00483                 } <span class="keywordflow">catch</span> (...) {
<a name="l00484"></a>00484                         P_TRACE(2, <span class="stringliteral">"An unknown exception occurred in a MessageServer client thread."</span>);
<a name="l00485"></a>00485                 }
<a name="l00486"></a>00486         }
<a name="l00487"></a>00487         
<a name="l00488"></a>00488 <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00489"></a>00489 <span class="comment">        /**</span>
<a name="l00490"></a>00490 <span class="comment">         * Creates a new MessageServer object.</span>
<a name="l00491"></a>00491 <span class="comment">         * The actual server main loop is not started until you call mainLoop().</span>
<a name="l00492"></a>00492 <span class="comment">         *</span>
<a name="l00493"></a>00493 <span class="comment">         * @param socketFilename The socket filename on which this MessageServer</span>
<a name="l00494"></a>00494 <span class="comment">         *                       should be listening.</span>
<a name="l00495"></a>00495 <span class="comment">         * @param accountsDatabase An accounts database for this server, used for</span>
<a name="l00496"></a>00496 <span class="comment">         *                         authenticating clients.</span>
<a name="l00497"></a>00497 <span class="comment">         * @throws RuntimeException Something went wrong while setting up the server socket.</span>
<a name="l00498"></a>00498 <span class="comment">         * @throws SystemException Something went wrong while setting up the server socket.</span>
<a name="l00499"></a>00499 <span class="comment">         * @throws boost::thread_interrupted</span>
<a name="l00500"></a>00500 <span class="comment">         */</span>
<a name="l00501"></a><a class="code" href="classPassenger_1_1MessageServer.html#4b6f33e66261116c2ec04b26e651dc18">00501</a>         <a class="code" href="classPassenger_1_1MessageServer.html#4b6f33e66261116c2ec04b26e651dc18" title="Creates a new MessageServer object.">MessageServer</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &amp;<a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>, AccountsDatabasePtr <a class="code" href="classPassenger_1_1MessageServer.html#4705130bf6626dd2201e7d73ead57b93" title="An accounts database, used for authenticating clients.">accountsDatabase</a>) {
<a name="l00502"></a>00502                 this-&gt;socketFilename   = socketFilename;
<a name="l00503"></a>00503                 this-&gt;accountsDatabase = accountsDatabase;
<a name="l00504"></a>00504                 <a class="code" href="classPassenger_1_1MessageServer.html#bf5075add15c5f32a60039bdcbe98926" title="The maximum number of milliseconds that client may spend on logging in.">loginTimeout</a> = 2000;
<a name="l00505"></a>00505                 <a class="code" href="classPassenger_1_1MessageServer.html#86f9ec99fe5dbed5c04d4b9e8f170995" title="Create a server socket and set it up for listening.">startListening</a>();
<a name="l00506"></a>00506         }
<a name="l00507"></a>00507         
<a name="l00508"></a>00508         ~<a class="code" href="classPassenger_1_1MessageServer.html" title="Simple pluggable request/response messaging server framework.">MessageServer</a>() {
<a name="l00509"></a>00509                 this_thread::disable_syscall_interruption dsi;
<a name="l00510"></a>00510                 syscalls::close(<a class="code" href="classPassenger_1_1MessageServer.html#ef3c642484fbbbfc46b7768c53a5c0d4" title="The server socket&amp;#39;s file descriptor.">serverFd</a>);
<a name="l00511"></a>00511                 syscalls::unlink(<a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>.c_str());
<a name="l00512"></a>00512         }
<a name="l00513"></a>00513         
<a name="l00514"></a>00514         <span class="keywordtype">string</span> getSocketFilename()<span class="keyword"> const </span>{
<a name="l00515"></a>00515                 <span class="keywordflow">return</span> <a class="code" href="classPassenger_1_1MessageServer.html#18f4966401ab1f1ef245af922b382ce3" title="The filename of the server socket on which this MessageServer is listening.">socketFilename</a>;
<a name="l00516"></a>00516         }
<a name="l00517"></a>00517         <span class="comment"></span>
<a name="l00518"></a>00518 <span class="comment">        /**</span>
<a name="l00519"></a>00519 <span class="comment">         * Starts the server main loop. This method will loop forever until some</span>
<a name="l00520"></a>00520 <span class="comment">         * other thread interrupts the calling thread, or until an exception is raised.</span>
<a name="l00521"></a>00521 <span class="comment">         *</span>
<a name="l00522"></a>00522 <span class="comment">         * @throws SystemException Unable to accept a new connection. If this is a</span>
<a name="l00523"></a>00523 <span class="comment">         *                         non-fatal error then you may call mainLoop() again</span>
<a name="l00524"></a>00524 <span class="comment">         *                         to restart the server main loop.</span>
<a name="l00525"></a>00525 <span class="comment">         * @throws boost::thread_interrupted The calling thread has been interrupted.</span>
<a name="l00526"></a>00526 <span class="comment">         */</span>
<a name="l00527"></a><a class="code" href="classPassenger_1_1MessageServer.html#af639d8228da241b957c707ef0f04c91">00527</a>         <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer.html#af639d8228da241b957c707ef0f04c91" title="Starts the server main loop.">mainLoop</a>() {
<a name="l00528"></a>00528                 TRACE_POINT();
<a name="l00529"></a>00529                 <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
<a name="l00530"></a>00530                         this_thread::interruption_point();
<a name="l00531"></a>00531                         sockaddr_un addr;
<a name="l00532"></a>00532                         socklen_t len = <span class="keyword">sizeof</span>(addr);
<a name="l00533"></a>00533                         <a class="code" href="classPassenger_1_1FileDescriptor.html" title="Wrapper class around a file descriptor integer, for RAII behavior.">FileDescriptor</a> fd;
<a name="l00534"></a>00534                         
<a name="l00535"></a>00535                         UPDATE_TRACE_POINT();
<a name="l00536"></a>00536                         fd = syscalls::accept(<a class="code" href="classPassenger_1_1MessageServer.html#ef3c642484fbbbfc46b7768c53a5c0d4" title="The server socket&amp;#39;s file descriptor.">serverFd</a>, (<span class="keyword">struct</span> sockaddr *) &amp;addr, &amp;len);
<a name="l00537"></a>00537                         <span class="keywordflow">if</span> (fd == -1) {
<a name="l00538"></a>00538                                 <span class="keywordflow">throw</span> <a class="code" href="classPassenger_1_1SystemException.html" title="Represents an error returned by a system call or a standard library call.">SystemException</a>(<span class="stringliteral">"Unable to accept a new client"</span>, errno);
<a name="l00539"></a>00539                         }
<a name="l00540"></a>00540                         
<a name="l00541"></a>00541                         UPDATE_TRACE_POINT();
<a name="l00542"></a>00542                         this_thread::disable_interruption di;
<a name="l00543"></a>00543                         this_thread::disable_syscall_interruption dsi;
<a name="l00544"></a>00544                         
<a name="l00545"></a>00545                         function&lt;void ()&gt; func(boost::bind(&amp;<a class="code" href="classPassenger_1_1MessageServer.html#c7d708f90b3a1b1ae5e7b215c688c95e" title="The main function for a thread which handles a client.">MessageServer::clientHandlingMainLoop</a>,
<a name="l00546"></a>00546                                 <span class="keyword">this</span>, fd));
<a name="l00547"></a>00547                         <span class="keywordtype">string</span> name = <span class="stringliteral">"MessageServer client thread "</span>;
<a name="l00548"></a>00548                         name.append(<a class="code" href="group__Support.html#gf6fab368d70c18fdf16bf5a24f630407" title="Convert anything to a string.">toString</a>(fd));
<a name="l00549"></a>00549                         <a class="code" href="classPassenger_1_1MessageServer.html#48ccf2c09c2c8b5dcfe3a0585dba67cf" title="The client threads.">threadGroup</a>.create_thread(func, name, CLIENT_THREAD_STACK_SIZE);
<a name="l00550"></a>00550                 }
<a name="l00551"></a>00551         }
<a name="l00552"></a>00552         <span class="comment"></span>
<a name="l00553"></a>00553 <span class="comment">        /**</span>
<a name="l00554"></a>00554 <span class="comment">         * Registers a new handler.</span>
<a name="l00555"></a>00555 <span class="comment">         * </span>
<a name="l00556"></a>00556 <span class="comment">         * @pre The main loop isn't running.</span>
<a name="l00557"></a>00557 <span class="comment">         */</span>
<a name="l00558"></a><a class="code" href="classPassenger_1_1MessageServer.html#8f5df648df67f85ab0b7317be21f643f">00558</a>         <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer.html#8f5df648df67f85ab0b7317be21f643f" title="Registers a new handler.">addHandler</a>(HandlerPtr handler) {
<a name="l00559"></a>00559                 <a class="code" href="classPassenger_1_1MessageServer.html#bced7a8e542f6ab4a81ac1b11f8d163a" title="The registered message handlers.">handlers</a>.push_back(handler);
<a name="l00560"></a>00560         }
<a name="l00561"></a>00561         <span class="comment"></span>
<a name="l00562"></a>00562 <span class="comment">        /**</span>
<a name="l00563"></a>00563 <span class="comment">         * Sets the maximum number of milliseconds that clients may spend on logging in.</span>
<a name="l00564"></a>00564 <span class="comment">         * Clients that take longer are disconnected.</span>
<a name="l00565"></a>00565 <span class="comment">         *</span>
<a name="l00566"></a>00566 <span class="comment">         * @pre timeout != 0</span>
<a name="l00567"></a>00567 <span class="comment">         * @pre The main loop isn't running.</span>
<a name="l00568"></a>00568 <span class="comment">         */</span>
<a name="l00569"></a><a class="code" href="classPassenger_1_1MessageServer.html#91571b29a8a88f80bab68f8083f59291">00569</a>         <span class="keywordtype">void</span> <a class="code" href="classPassenger_1_1MessageServer.html#91571b29a8a88f80bab68f8083f59291" title="Sets the maximum number of milliseconds that clients may spend on logging in.">setLoginTimeout</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">long</span> timeout) {
<a name="l00570"></a>00570                 assert(timeout != 0);
<a name="l00571"></a>00571                 <a class="code" href="classPassenger_1_1MessageServer.html#bf5075add15c5f32a60039bdcbe98926" title="The maximum number of milliseconds that client may spend on logging in.">loginTimeout</a> = timeout;
<a name="l00572"></a>00572         }
<a name="l00573"></a>00573 };
<a name="l00574"></a>00574 
<a name="l00575"></a>00575 <span class="keyword">typedef</span> shared_ptr&lt;MessageServer&gt; MessageServerPtr;
<a name="l00576"></a>00576 
<a name="l00577"></a>00577 } <span class="comment">// namespace Passenger</span>
<a name="l00578"></a>00578 
<a name="l00579"></a>00579 <span class="preprocessor">#endif </span><span class="comment">/* _PASSENGER_MESSAGE_SERVER_H_ */</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Feb 21 12:22:45 2010 for Passenger by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>
</body>
</html>