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
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>buf_server.h</h1><a href="buf__server_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025
00026 <font class="preprocessor">#ifndef NL_BUF_SERVER_H</font>
00027 <font class="preprocessor"></font><font class="preprocessor">#define NL_BUF_SERVER_H</font>
00028 <font class="preprocessor"></font>
00029 <font class="preprocessor">#include "<a class="code" href="types__nl_8h.html">nel/misc/types_nl.h</a>"</font>
00030 <font class="preprocessor">#include "<a class="code" href="buf__net__base_8h.html">nel/net/buf_net_base.h</a>"</font>
00031 <font class="preprocessor">#include "<a class="code" href="listen__sock_8h.html">nel/net/listen_sock.h</a>"</font>
00032 <font class="preprocessor">#include "<a class="code" href="buf__sock_8h.html">nel/net/buf_sock.h</a>"</font>
00033 <font class="preprocessor">#include <list></font>
00034 <font class="preprocessor">#include <set></font>
00035
00036 <font class="comment">// POLL1 (ignore POLL comments)</font>
00037
00038 <font class="keyword">namespace </font>NLNET {
00039
00040
00041 <font class="keyword">class </font>CInetAddress;
00042 <font class="keyword">class </font>CBufServer;
00043
00044
<a name="l00048"></a><a class="code" href="classNLNET_1_1CServerTask.html">00048</a> <font class="keyword">class </font>CServerTask
00049 {
00050 <font class="keyword">public</font>:
00051
00053 <font class="keyword">virtual</font> <a class="code" href="classNLNET_1_1CServerTask.html#a0">~CServerTask</a>();
00054
<a name="l00056"></a><a class="code" href="classNLNET_1_1CServerTask.html#a1">00056</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CServerTask.html#a1">requireExit</a>() { <a class="code" href="classNLNET_1_1CServerTask.html#o0">_ExitRequired</a> = <font class="keyword">true</font>; }
00057
00058 <font class="preprocessor">#ifdef NL_OS_UNIX</font>
00059 <font class="preprocessor"></font>
00060 <font class="keywordtype">void</font> wakeUp();
00061 <font class="preprocessor">#endif</font>
00062 <font class="preprocessor"></font>
00063 <font class="keyword">protected</font>:
00064
00066 <a class="code" href="classNLNET_1_1CServerTask.html#b0">CServerTask</a>();
00067
<a name="l00069"></a><a class="code" href="classNLNET_1_1CServerTask.html#b1">00069</a> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CServerTask.html#b1">exitRequired</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CServerTask.html#o0">_ExitRequired</a>; }
00070
00071 <font class="preprocessor">#ifdef NL_OS_UNIX</font>
00072 <font class="preprocessor"></font>
00073 <font class="keywordtype">int</font> _WakeUpPipeHandle [2];
00074 <font class="preprocessor">#endif</font>
00075 <font class="preprocessor"></font>
00076 <font class="keyword">private</font>:
00077
<a name="l00078"></a><a class="code" href="classNLNET_1_1CServerTask.html#o0">00078</a> <font class="keyword">volatile</font> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CServerTask.html#o0">_ExitRequired</a>;
00079 };
00080
00081
<a name="l00085"></a><a class="code" href="classNLNET_1_1CListenTask.html">00085</a> <font class="keyword">class </font>CListenTask : <font class="keyword">public</font> NLMISC::IRunnable, <font class="keyword">public</font> CServerTask
00086 {
00087 <font class="keyword">public</font>:
00088
<a name="l00090"></a><a class="code" href="classNLNET_1_1CListenTask.html#a0">00090</a> <a class="code" href="classNLNET_1_1CListenTask.html#a0">CListenTask</a>( CBufServer *server ) : <a class="code" href="classNLNET_1_1CServerTask.html#b0">CServerTask</a>(), <a class="code" href="classNLNET_1_1CListenTask.html#o0">_Server</a>(server) {}
00091
00093 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CListenTask.html#a1">init</a>( uint16 port );
00094
00096 <font class="keyword">virtual</font> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CListenTask.html#a2">run</a>();
00097
<a name="l00099"></a><a class="code" href="classNLNET_1_1CListenTask.html#a3">00099</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CListenTask.html#a3">close</a>() { <a class="code" href="classNLNET_1_1CListenTask.html#o1">_ListenSock</a>.close(); }
00100
<a name="l00102"></a><a class="code" href="classNLNET_1_1CListenTask.html#a4">00102</a> <font class="keyword">const</font> CInetAddress& <a class="code" href="classNLNET_1_1CListenTask.html#a4">localAddr</a>() { <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CListenTask.html#o1">_ListenSock</a>.localAddr(); }
00103
00104 <font class="keyword">private</font>:
00105
<a name="l00106"></a><a class="code" href="classNLNET_1_1CListenTask.html#o0">00106</a> CBufServer *<a class="code" href="classNLNET_1_1CListenTask.html#o0">_Server</a>;
<a name="l00107"></a><a class="code" href="classNLNET_1_1CListenTask.html#o1">00107</a> CListenSock <a class="code" href="classNLNET_1_1CListenTask.html#o1">_ListenSock</a>;
00108
00109 };
00110
00111
00112 <font class="keyword">typedef</font> std::vector<NLMISC::IThread*> <a class="code" href="namespaceNLNET.html#a7">CThreadPool</a>;
00113
00114
00115 <font class="comment">// Mode: Small server</font>
00116 <font class="preprocessor">#undef PRESET_BIG_SERVER</font>
00117 <font class="preprocessor"></font>
00118 <font class="preprocessor">#ifdef PRESET_BIG_SERVER</font>
00119 <font class="preprocessor"></font><font class="comment">// Big server</font>
00120 <font class="preprocessor">#define DEFAULT_STRATEGY SpreadSockets</font>
00121 <font class="preprocessor"></font><font class="preprocessor">#define DEFAULT_MAX_THREADS 64</font>
00122 <font class="preprocessor"></font><font class="preprocessor">#define DEFAULT_MAX_SOCKETS_PER_THREADS 64</font>
00123 <font class="preprocessor"></font><font class="preprocessor">#else</font>
00124 <font class="preprocessor"></font><font class="comment">// Small server</font>
<a name="l00125"></a><a class="code" href="buf__server_8h.html#a0">00125</a> <font class="preprocessor">#define DEFAULT_STRATEGY FillThreads</font>
<a name="l00126"></a><a class="code" href="buf__server_8h.html#a1">00126</a> <font class="preprocessor"></font><font class="preprocessor">#define DEFAULT_MAX_THREADS 64</font>
<a name="l00127"></a><a class="code" href="buf__server_8h.html#a2">00127</a> <font class="preprocessor"></font><font class="preprocessor">#define DEFAULT_MAX_SOCKETS_PER_THREADS 16</font>
00128 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00129 <font class="preprocessor"></font>
00130
<a name="l00153"></a><a class="code" href="classNLNET_1_1CBufServer.html">00153</a> <font class="keyword">class </font>CBufServer : <font class="keyword">public</font> CBufNetBase
00154 {
00155 <font class="keyword">public</font>:
00156
<a name="l00157"></a><a class="code" href="classNLNET_1_1CBufServer.html#s2">00157</a> <font class="keyword">enum</font> <a class="code" href="classNLNET_1_1CBufServer.html#s2">TThreadStategy</a> { <a class="code" href="classNLNET_1_1CBufServer.html#s2s0">SpreadSockets</a>, <a class="code" href="classNLNET_1_1CBufServer.html#s2s1">FillThreads</a> };
00158
00162 <a class="code" href="classNLNET_1_1CBufServer.html#a0">CBufServer</a>( <a class="code" href="classNLNET_1_1CBufServer.html#s2">TThreadStategy</a> strategy=<a class="code" href="buf__server_8h.html#a0">DEFAULT_STRATEGY</a>,
00163 uint16 max_threads=<a class="code" href="buf__server_8h.html#a1">DEFAULT_MAX_THREADS</a>,
00164 uint16 max_sockets_per_thread=<a class="code" href="buf__server_8h.html#a2">DEFAULT_MAX_SOCKETS_PER_THREADS</a>,
00165 <font class="keywordtype">bool</font> nodelay=<font class="keyword">true</font>, <font class="keywordtype">bool</font> replaymode=<font class="keyword">false</font> );
00166
00168 <font class="keyword">virtual</font> <a class="code" href="classNLNET_1_1CBufServer.html#a1">~CBufServer</a>();
00169
00171 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a2">init</a>( uint16 port );
00172
00178 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a3">disconnect</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid, <font class="keywordtype">bool</font> quick=<font class="keyword">false</font> );
00179
<a name="l00181"></a><a class="code" href="classNLNET_1_1CBufServer.html#a4">00181</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a4">setConnectionCallback</a>( <a class="code" href="namespaceNLNET.html#a2">TNetCallback</a> cb, <font class="keywordtype">void</font>* arg ) { <a class="code" href="classNLNET_1_1CBufServer.html#o7">_ConnectionCallback</a> = cb; <a class="code" href="classNLNET_1_1CBufServer.html#o8">_ConnectionCbArg</a> = arg; }
00182
00183
00184
00187 <font class="comment">//void send( const std::vector<uint8>& buffer, TSockId hostid );</font>
00188 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a5">send</a>( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMemStream.html">NLMISC::CMemStream</a>& buffer, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid );
00189
00193 <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CBufServer.html#a6">dataAvailable</a>();
00194
00198 <font class="comment">//void receive( std::vector<uint8>& buffer, TSockId* hostid );</font>
00199 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a7">receive</a>( <a class="code" href="classNLMISC_1_1CMemStream.html">NLMISC::CMemStream</a>& buffer, <a class="code" href="namespaceNLNET.html#a0">TSockId</a>* hostid );
00200
00202 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a8">update</a>();
00203
00204
00205
00206
00207 <font class="comment">// Returns the size in bytes of the data stored in the send queue.</font>
00208 uint32 <a class="code" href="classNLNET_1_1CBufServer.html#a9">getSendQueueSize</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> destid );
00209
<a name="l00213"></a><a class="code" href="classNLNET_1_1CBufServer.html#a10">00213</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a10">setTimeFlushTrigger</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> destid, sint32 ms ) { <a class="code" href="debug_8h.html#a6">nlassert</a>( destid != InvalidSockId ); destid->setTimeFlushTrigger( ms ); }
00214
<a name="l00218"></a><a class="code" href="classNLNET_1_1CBufServer.html#a11">00218</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#a11">setSizeFlushTrigger</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> destid, sint32 size ) { <a class="code" href="debug_8h.html#a6">nlassert</a>( destid != InvalidSockId ); destid->setSizeFlushTrigger( size ); }
00219
<a name="l00224"></a><a class="code" href="classNLNET_1_1CBufServer.html#a12">00224</a> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CBufServer.html#a12">flush</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> destid ) { <a class="code" href="debug_8h.html#a6">nlassert</a>( destid != InvalidSockId ); <font class="keywordflow">return</font> destid->flush(); }
00225
00226
00227
00228
<a name="l00230"></a><a class="code" href="classNLNET_1_1CBufServer.html#a13">00230</a> <font class="keyword">const</font> CInetAddress& <a class="code" href="classNLNET_1_1CBufServer.html#a13">listenAddress</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o4">_ListenTask</a>->localAddr(); }
00231
<a name="l00233"></a><a class="code" href="classNLNET_1_1CBufServer.html#a14">00233</a> <font class="keyword">const</font> CInetAddress& <a class="code" href="classNLNET_1_1CBufServer.html#a14">hostAddress</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid ) { <a class="code" href="debug_8h.html#a6">nlassert</a>( hostid != InvalidSockId ); <font class="keywordflow">return</font> hostid->Sock->remoteAddr(); }
00234
00235 <font class="comment">/*</font>
00237 <font class="comment"> uint32 bytesDownloaded()</font>
00238 <font class="comment"> {</font>
00239 <font class="comment"> NLMISC::CSynchronized<uint32>::CAccessor syncbpi ( &_BytesPushedIn );</font>
00240 <font class="comment"> return syncbpi.value();</font>
00241 <font class="comment"> }</font>
00243 <font class="comment"> uint32 newBytesDownloaded();</font>
00244 <font class="comment"> */</font>
00245
<a name="l00247"></a><a class="code" href="classNLNET_1_1CBufServer.html#a15">00247</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#a15">bytesReceived</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o10">_BytesPoppedIn</a>; }
00248
00250 uint64 <a class="code" href="classNLNET_1_1CBufServer.html#a16">newBytesReceived</a>();
00251
<a name="l00253"></a><a class="code" href="classNLNET_1_1CBufServer.html#a17">00253</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#a17">bytesSent</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o9">_BytesPushedOut</a>; }
00254
00256 uint64 <a class="code" href="classNLNET_1_1CBufServer.html#a18">newBytesSent</a>();
00257
<a name="l00259"></a><a class="code" href="classNLNET_1_1CBufServer.html#a19">00259</a> uint32 <a class="code" href="classNLNET_1_1CBufServer.html#a19">nbConnections</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o13">_NbConnections</a>; }
00260
00261 <font class="keyword">protected</font>:
00262
<a name="l00263"></a><a class="code" href="classNLNET_1_1CBufServer.html#l0">00263</a> <font class="keyword">friend</font> <font class="keyword">class </font><a class="code" href="classNLNET_1_1CBufServer.html#l0">CServerBufSock</a>;
<a name="l00264"></a><a class="code" href="classNLNET_1_1CBufServer.html#l1">00264</a> <font class="keyword">friend</font> <font class="keyword">class </font><a class="code" href="classNLNET_1_1CBufServer.html#l1">CListenTask</a>;
<a name="l00265"></a><a class="code" href="classNLNET_1_1CBufServer.html#l2">00265</a> <font class="keyword">friend</font> <font class="keyword">class </font><a class="code" href="classNLNET_1_1CBufServer.html#l2">CServerReceiveTask</a>;
00266
<a name="l00268"></a><a class="code" href="classNLNET_1_1CBufServer.html#b0">00268</a> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CBufServer.html#b0">noDelay</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o0">_NoDelay</a>; }
00269
00273 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#b1">dispatchNewSocket</a>( <a class="code" href="classNLNET_1_1CBufServer.html#l0">CServerBufSock</a> *bufsock );
00274
<a name="l00276"></a><a class="code" href="classNLNET_1_1CBufServer.html#b2">00276</a> <a class="code" href="classNLNET_1_1CBufServer.html#l2">CServerReceiveTask</a> *<a class="code" href="classNLNET_1_1CBufServer.html#b2">receiveTask</a>( std::vector<NLMISC::IThread*>::iterator ipt )
00277 {
00278 <font class="keywordflow">return</font> ((<a class="code" href="classNLNET_1_1CBufServer.html#l2">CServerReceiveTask</a>*)((*ipt)->getRunnable()));
00279 }
00280
00282 <font class="comment">/*void pushBufferToHost( const std::vector<uint8>& buffer, TSockId hostid )</font>
00283 <font class="comment"> {</font>
00284 <font class="comment"> if ( hostid->pushBuffer( buffer ) )</font>
00285 <font class="comment"> {</font>
00286 <font class="comment"> _BytesPushedOut += buffer.size() + sizeof(TBlockSize); // statistics</font>
00287 <font class="comment"> }</font>
00288 <font class="comment"> }*/</font>
00289
<a name="l00290"></a><a class="code" href="classNLNET_1_1CBufServer.html#b3">00290</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#b3">pushBufferToHost</a>( <font class="keyword">const</font> <a class="code" href="classNLMISC_1_1CMemStream.html">NLMISC::CMemStream</a>& buffer, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> hostid )
00291 {
00292 <a class="code" href="debug_8h.html#a6">nlassert</a>( hostid != InvalidSockId );
00293 <font class="keywordflow">if</font> ( hostid->pushBuffer( buffer ) )
00294 {
00295 <a class="code" href="classNLNET_1_1CBufServer.html#o9">_BytesPushedOut</a> += buffer.<a class="code" href="classNLMISC_1_1CMemStream.html#a10">length</a>() + <font class="keyword">sizeof</font>(TBlockSize); <font class="comment">// statistics</font>
00296 }
00297 }
00298
00299 <font class="comment">// Creates a new task and run a new thread for it</font>
00300 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CBufServer.html#b4">addNewThread</a>( <a class="code" href="namespaceNLNET.html#a7">CThreadPool</a>& threadpool, <a class="code" href="classNLNET_1_1CBufServer.html#l0">CServerBufSock</a> *bufsock );
00301
<a name="l00303"></a><a class="code" href="classNLNET_1_1CBufServer.html#b5">00303</a> <a class="code" href="namespaceNLNET.html#a2">TNetCallback</a> <a class="code" href="classNLNET_1_1CBufServer.html#b5">connectionCallback</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o7">_ConnectionCallback</a>; }
00304
<a name="l00306"></a><a class="code" href="classNLNET_1_1CBufServer.html#b6">00306</a> <font class="keywordtype">void</font>* <a class="code" href="classNLNET_1_1CBufServer.html#b6">argOfConnectionCallback</a>()<font class="keyword"> const </font>{ <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CBufServer.html#o8">_ConnectionCbArg</a>; }
00307
00308 <font class="comment">/*</font>
00309 <font class="comment"> NLMISC::CSynchronized<uint32>& syncBytesPushedIn() { return _BytesPushedIn; }</font>
00310 <font class="comment"> */</font>
00311
00312 <font class="keyword">private</font>:
00313
<a name="l00315"></a><a class="code" href="classNLNET_1_1CBufServer.html#o0">00315</a> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CBufServer.html#o0">_NoDelay</a>;
00316
<a name="l00318"></a><a class="code" href="classNLNET_1_1CBufServer.html#o1">00318</a> <a class="code" href="classNLNET_1_1CBufServer.html#s2">TThreadStategy</a> <a class="code" href="classNLNET_1_1CBufServer.html#o1">_ThreadStrategy</a>;
00319
<a name="l00321"></a><a class="code" href="classNLNET_1_1CBufServer.html#o2">00321</a> uint16 <a class="code" href="classNLNET_1_1CBufServer.html#o2">_MaxThreads</a>;
00322
<a name="l00324"></a><a class="code" href="classNLNET_1_1CBufServer.html#o3">00324</a> uint16 <a class="code" href="classNLNET_1_1CBufServer.html#o3">_MaxSocketsPerThread</a>;
00325
<a name="l00327"></a><a class="code" href="classNLNET_1_1CBufServer.html#o4">00327</a> <a class="code" href="classNLNET_1_1CBufServer.html#l1">CListenTask</a> *<a class="code" href="classNLNET_1_1CBufServer.html#o4">_ListenTask</a>;
00328
<a name="l00330"></a><a class="code" href="classNLNET_1_1CBufServer.html#o5">00330</a> <a class="code" href="classNLMISC_1_1IThread.html">NLMISC::IThread</a> *<a class="code" href="classNLNET_1_1CBufServer.html#o5">_ListenThread</a>;
00331
00332 <font class="comment">/* Vector of receiving threads.</font>
00333 <font class="comment"> * Thread: thread control</font>
00334 <font class="comment"> * Thread->Runnable: access to the CServerReceiveTask object</font>
00335 <font class="comment"> * Thread->getRunnable()->sock(): access to the socket</font>
00336 <font class="comment"> * The purpose of this list is to delete the objects after use.</font>
00337 <font class="comment"> */</font>
<a name="l00338"></a><a class="code" href="classNLNET_1_1CBufServer.html#o6">00338</a> NLMISC::CSynchronized<CThreadPool> <a class="code" href="classNLNET_1_1CBufServer.html#o6">_ThreadPool</a>;
00339
<a name="l00341"></a><a class="code" href="classNLNET_1_1CBufServer.html#o7">00341</a> <a class="code" href="namespaceNLNET.html#a2">TNetCallback</a> <a class="code" href="classNLNET_1_1CBufServer.html#o7">_ConnectionCallback</a>;
00342
<a name="l00344"></a><a class="code" href="classNLNET_1_1CBufServer.html#o8">00344</a> <font class="keywordtype">void</font>* <a class="code" href="classNLNET_1_1CBufServer.html#o8">_ConnectionCbArg</a>;
00345
<a name="l00347"></a><a class="code" href="classNLNET_1_1CBufServer.html#o9">00347</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#o9">_BytesPushedOut</a>;
00348
<a name="l00350"></a><a class="code" href="classNLNET_1_1CBufServer.html#o10">00350</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#o10">_BytesPoppedIn</a>;
00351
<a name="l00353"></a><a class="code" href="classNLNET_1_1CBufServer.html#o11">00353</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#o11">_PrevBytesPoppedIn</a>;
00354
<a name="l00356"></a><a class="code" href="classNLNET_1_1CBufServer.html#o12">00356</a> uint64 <a class="code" href="classNLNET_1_1CBufServer.html#o12">_PrevBytesPushedOut</a>;
00357
<a name="l00359"></a><a class="code" href="classNLNET_1_1CBufServer.html#o13">00359</a> uint32 <a class="code" href="classNLNET_1_1CBufServer.html#o13">_NbConnections</a>;
00360
<a name="l00362"></a><a class="code" href="classNLNET_1_1CBufServer.html#o14">00362</a> <font class="keywordtype">bool</font> <a class="code" href="classNLNET_1_1CBufServer.html#o14">_ReplayMode</a>;
00363
00364 <font class="comment">/*</font>
00366 <font class="comment"> NLMISC::CSynchronized<uint32> _BytesPushedIn;</font>
00367 <font class="comment"></font>
00369 <font class="comment"> uint32 _PrevBytesPushedIn;</font>
00370 <font class="comment"> */</font>
00371 };
00372
00373
00374 <font class="keyword">typedef</font> std::set<TSockId> <a class="code" href="namespaceNLNET.html#a8">CConnections</a>;
00375
00376 <font class="comment">/*</font>
00377 <font class="comment">// Workaround for Internal Compiler Error in debug mode with MSVC6</font>
00378 <font class="comment">#ifdef NL_RELEASE</font>
00379 <font class="comment">typedef CConnections::iterator ItConnection;</font>
00380 <font class="comment">#else</font>
00381 <font class="comment">typedef TSockId ItConnection;</font>
00382 <font class="comment">#endif</font>
00383 <font class="comment">// Set of iterators to connections (set because we must not add an element twice) </font>
00384 <font class="comment">typedef std::set<ItConnection> CItConnections;</font>
00385 <font class="comment">*/</font>
00386
00387
00388 <font class="preprocessor">#ifdef NL_OS_UNIX</font>
00389 <font class="preprocessor"></font>
00390 <font class="keyword">enum</font> TPipeWay { PipeRead, PipeWrite };
00391 <font class="preprocessor">#endif</font>
00392 <font class="preprocessor"></font>
00393
00394 <font class="comment">// POLL2</font>
00395
00396
<a name="l00402"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html">00402</a> <font class="keyword">class </font>CServerReceiveTask : <font class="keyword">public</font> NLMISC::IRunnable, <font class="keyword">public</font> CServerTask
00403 {
00404 <font class="keyword">public</font>:
00405
<a name="l00407"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#a0">00407</a> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a0">CServerReceiveTask</a>( <a class="code" href="classNLNET_1_1CServerReceiveTask.html#l0">CBufServer</a> *<a class="code" href="classNLNET_1_1CServerReceiveTask.html#a6">server</a> ) : <a class="code" href="classNLNET_1_1CServerTask.html#b0">CServerTask</a>(), <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o0">_Server</a>(<a class="code" href="classNLNET_1_1CServerReceiveTask.html#a6">server</a>), <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">_Connections</a>("<a class="code" href="classNLNET_1_1CServerReceiveTask.html#a0">CServerReceiveTask</a>::<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">_Connections</a>"), <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o2">_RemoveSet</a>("<a class="code" href="classNLNET_1_1CServerReceiveTask.html#a0">CServerReceiveTask</a>::<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o2">_RemoveSet</a>") {}
00408
00410 <font class="keyword">virtual</font> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a1">run</a>();
00411
<a name="l00413"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#a2">00413</a> uint <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a2">numberOfConnections</a>()
00414 {
00415 uint nb;
00416 {
00417 NLMISC::CSynchronized<CConnections>::CAccessor connectionssync( &<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">_Connections</a> );
00418 nb = connectionssync.value().size();
00419 }
00420 <font class="keywordflow">return</font> nb;
00421 }
00422
<a name="l00424"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#a3">00424</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a3">addNewSocket</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> sockid )
00425 {
00426 <font class="comment">//nlnettrace( "CServerReceiveTask::addNewSocket" );</font>
00427 <a class="code" href="debug_8h.html#a6">nlassert</a>( sockid != InvalidSockId );
00428 {
00429 NLMISC::CSynchronized<CConnections>::CAccessor connectionssync( &<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">_Connections</a> );
00430 connectionssync.value().insert( sockid );
00431 }
00432 <font class="comment">// POLL3</font>
00433 }
00434
00435 <font class="comment">// POLL4</font>
00436
<a name="l00441"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#a4">00441</a> <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a4">addToRemoveSet</a>( <a class="code" href="namespaceNLNET.html#a0">TSockId</a> sockid )
00442 {
00443 <a class="code" href="buf__sock_8h.html#a0">nlnettrace</a>( <font class="stringliteral">"CServerReceiveTask::addToRemoveSet"</font> );
00444 <a class="code" href="debug_8h.html#a6">nlassert</a>( sockid != InvalidSockId );
00445 {
00446 <font class="comment">// Three possibilities :</font>
00447 <font class="comment">// - The value is inserted into the set.</font>
00448 <font class="comment">// - The value is already present in the set.</font>
00449 <font class="comment">// - The set is locked by a receive thread which is removing the closed connections.</font>
00450 <font class="comment">// When the set gets unlocked, it is empty so the value is inserted. It means the</font>
00451 <font class="comment">// value could be already in the set before it was cleared.</font>
00452 <font class="comment">// Note: with a fonction such as tryAcquire(), we could avoid to enter the mutex</font>
00453 <font class="comment">// when it is already locked</font>
00454 <font class="comment">// See clearClosedConnections().</font>
00455 NLMISC::CSynchronized<CConnections>::CAccessor removesetsync( &<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o2">_RemoveSet</a> );
00456 removesetsync.value().insert( sockid );
00457 <font class="comment">//nldebug( "LNETL1: ic: %p - RemoveSet.size(): %d", ic, removesetsync.value().size() );</font>
00458 }
00459 <font class="preprocessor">#ifdef NL_OS_UNIX</font>
00460 <font class="preprocessor"></font> wakeUp();
00461 <font class="preprocessor">#endif</font>
00462 <font class="preprocessor"></font> }
00463
00465 <font class="keywordtype">void</font> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#a5">clearClosedConnections</a>();
00466
<a name="l00468"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#a6">00468</a> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#l0">CBufServer</a> *<a class="code" href="classNLNET_1_1CServerReceiveTask.html#a6">server</a>() { <font class="keywordflow">return</font> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o0">_Server</a>; }
00469
<a name="l00470"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#l0">00470</a> <font class="keyword">friend</font> <font class="keyword">class </font><a class="code" href="classNLNET_1_1CServerReceiveTask.html#l0">CBufServer</a>;
00471
00472 <font class="keyword">private</font>:
00473
<a name="l00474"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#o0">00474</a> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#l0">CBufServer</a> *<a class="code" href="classNLNET_1_1CServerReceiveTask.html#o0">_Server</a>;
00475
00476 <font class="comment">/* List of sockets and send buffer.</font>
00477 <font class="comment"> * A TSockId is a pointer to a CBufSock object</font>
00478 <font class="comment"> */</font>
<a name="l00479"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">00479</a> NLMISC::CSynchronized<CConnections> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o1">_Connections</a>;
00480
00481 <font class="comment">// Connections to remove</font>
<a name="l00482"></a><a class="code" href="classNLNET_1_1CServerReceiveTask.html#o2">00482</a> NLMISC::CSynchronized<CConnections> <a class="code" href="classNLNET_1_1CServerReceiveTask.html#o2">_RemoveSet</a>;
00483
00484 <font class="comment">// POLL5</font>
00485
00486 };
00487
00488
00489 } <font class="comment">// NLNET</font>
00490
00491
00492 <font class="preprocessor">#endif // NL_BUF_SERVER_H</font>
00493 <font class="preprocessor"></font>
00494 <font class="comment">/* End of buf_server.h */</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|