📄 server_8h-source.html
字号:
00278 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, NLshort out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00279 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, NLulong out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00280 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, NLlong out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00281 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, NLfloat out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00282 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, NLdouble out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00283 <span class="keywordtype">int</span> chan_write(<span class="keywordtype">int</span> client_id, <span class="keywordtype">int</span> channel_id, std::string out, <span class="keywordtype">bool</span> timeout_is_failure = <span class="keyword">true</span>, <span class="keywordtype">double</span> timeout = 3.0);00284 00285 <span class="comment">//---- TCP CHANNELS CALLBACKS ----------------------------------------</span>00286 00287 <span class="comment">//listen socket is telling the leet client/server of new connection.</span>00288 <span class="keyword">virtual</span> <span class="keywordtype">void</span> listen_socket_incoming_connection(listen_socket_c *ls, NLsocket sock);00289 00290 <span class="comment">//station channel callback: channel opened ok</span>00291 <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_opened(<span class="keywordtype">int</span> channel_id, <a class="code" href="classchannel__c.html">channel_c</a> *ch, <span class="keywordtype">int</span> tag);00292 00293 <span class="comment">//station channel callback: channel open failed</span>00294 <span class="keyword">virtual</span> <span class="keywordtype">void</span> station_channel_failed(<span class="keywordtype">int</span> channel_id, <span class="keywordtype">int</span> code_reason, <span class="keywordtype">int</span> tag);00295 00296 <span class="comment">//---- THREAD CALLBACKS ----------------------------------------------</span>00297 00298 <span class="comment">//reader thread function for a client</span>00299 <span class="keywordtype">void</span> *reader_thread_run(<span class="keywordtype">void</span> *remote_client_c_cl);00300 00301 <span class="comment">//data just arrived in a client's "station"</span>00302 <span class="keywordtype">void</span> incoming_client_data(remote_client_c *cl, <a class="code" href="classbuffer__c.html">buffer_c</a> &in, <span class="keywordtype">int</span> packet_id);00303 00304 <span class="keyword">protected</span>:00305 00306 <span class="comment">//thread callback - disconnect a client (1)</span>00307 <span class="keywordtype">void</span> *disconnector_thread_run(<span class="keywordtype">void</span> *remote_client_c_cl, <span class="keywordtype">void</span> *int_timeout, <span class="keywordtype">void</span> *buffer_c_thrbuf);00308 00309 <span class="comment">//thread callback - disconnect a client (2)</span>00310 <span class="keywordtype">void</span> *disconnector_thread_run_2(<span class="keywordtype">void</span> *NLaddress_claddr, <span class="keywordtype">void</span> *int_timeout, <span class="keywordtype">void</span> *buffer_c_thrbuf);00311 00312 <span class="comment">//thread run - read from "sock" until has to quit</span>00313 <span class="keywordtype">void</span> *reqthread_thread_run(<span class="keywordtype">void</span> *);00314 00315 <span class="comment">//thread run - keeps checking clients to see if somebody timed out</span>00316 <span class="keywordtype">void</span> *timeout_thread_run(<span class="keywordtype">void</span> *);00317 00318 <span class="comment">//thread run - polls all client sockets when using ZIG_SERVER_THREADING_1_N</span>00319 <span class="keywordtype">void</span> *poll_thread_run(<span class="keywordtype">void</span> *);00320 00321 <span class="comment">//shared code -- reqthread_thread_run() and poll_sockets() -- reads the server request socket and processes the requests</span>00322 <span class="keywordtype">void</span> process_requests(<span class="keywordtype">int</span> result, <a class="code" href="classbuffer__c.html">buffer_c</a> pkt);00323 00324 <span class="comment">//shared code -- timeout_thread_run() and poll_sockets() -- checks for client timeouts</span>00325 <span class="keywordtype">void</span> process_timeouts();00326 00327 <span class="comment">//shared code -- poll_thread_run() and poll_sockets() -- polls client sockets and processes any data arrived from clients</span>00328 NLint process_clients(<span class="keywordtype">int</span> poll_timeout_ms);00329 00330 <span class="comment">//just another obscure function</span>00331 <span class="keywordtype">void</span> client_disconnection_finalization(remote_client_c *cl);00332 00333 <span class="comment">//get client for id</span>00334 remote_client_c *get_client(<span class="keywordtype">int</span> client_id);00335 00336 <span class="comment">//effectively sends the message</span>00337 <span class="keywordtype">int</span> send_message(remote_client_c *cl, <a class="code" href="classbuffer__c.html">buffer_c</a> &message, <span class="keywordtype">int</span> policy = RSP_USE_DEFAULT);00338 00339 <span class="comment">//delete a client</span>00340 <span class="keywordtype">void</span> delete_client(remote_client_c *cl);00341 00342 <span class="comment">//disconnect operations left to complete</span>00343 atomic_counter_c disc_left;00344 00345 <span class="comment">//boolean state: server already start()'ed?</span>00346 <span class="keywordtype">bool</span> started;00347 00348 <span class="comment">//port</span>00349 <span class="keywordtype">int</span> port, channel_port;00350 00351 <span class="comment">//maxplayers</span>00352 <span class="keywordtype">int</span> maxplayers;00353 00354 <span class="comment">//server behavior</span>00355 server_behavior_i *beh;00356 00357 <span class="comment">//thread/socket for reading requests</span>00358 NLsocket sock;00359 thread_c<server_c> reqthread;00360 <span class="keywordtype">bool</span> reqthread_quit; <span class="comment">//flag for thread quitting it's run method</span>00361 00362 <span class="comment">//clients map <client_id --> (client data record)></span>00363 std::map<int, remote_client_c*> clients;00364 mutex_c climutex; <span class="comment">//mutex for accessing "clients" map</span>00365 00366 <span class="comment">//client timeout, in seconds</span>00367 <span class="keywordtype">int</span> client_timeout;00368 <span class="keywordtype">bool</span> timeout_thread_quit;00369 thread_c<server_c> timeout_thread; <span class="comment">//client timeout thread. specially created to detect dropped clients! </span>00370 00371 <span class="comment">//mutex for stop()</span>00372 mutex_c stop_mutex;00373 00374 <span class="comment">//thread priorities to apply to new threads</span>00375 <span class="keywordtype">int</span> threads_prio;00376 00377 <span class="comment">//my local compression config flag. it is applied to all the new clients. -999 is a magic value that</span>00378 <span class="comment">//specifies that the flag is not initialized yet (so let the default from station.h be used)</span>00379 <span class="keywordtype">int</span> server_compression_config; <span class="comment">// = -999; this value set at the constructor</span>00380 00381 <span class="comment">//threading_strategy set by the last successful start()</span>00382 <span class="keywordtype">int</span> threading_strategy;00383 00384 <span class="comment">//NEW: socket group for all client sockets (for non-1:1 threading scheme)</span>00385 <span class="keywordtype">int</span> client_sockets_group;00386 00387 <span class="comment">//NEW: map for quickly obtaining the remote_client_c* by way of it's station's connected NLsocket</span>00388 map<NLsocket, remote_client_c*> clients_by_NLsocket;00389 mutex_c clients_by_NLsocket_mutex;00390 00391 <span class="comment">//NEW: thread for polling all the client sockets (1_N)</span>00392 <span class="keywordtype">bool</span> poll_thread_quit;00393 thread_c<server_c> poll_thread;00394 00395 <span class="comment">// REVIEW: if each socket is 32bits/4bytes, then 65536 sockets will use 256KB of stack </span>00396 <span class="comment">// just for a buffer, which is kind of wasteful...</span>00397 <span class="comment">// better would be to dynamically increase the buffer size as REAL user needs manifest </span>00398 <span class="comment">// themselves.</span>00399 <span class="preprocessor"> #define POLL_THREAD_SOCKET_BUFFER_SIZE HARDCODED_CLIENT_LIMIT</span>00400 <span class="preprocessor"></span> NLsocket socket_buffer[POLL_THREAD_SOCKET_BUFFER_SIZE]; <span class="comment">// one socket</span>00401 00402 <span class="comment">//the default send message policy configured by set_default_send_message_policy()</span>00403 <span class="keywordtype">int</span> default_send_message_policy;00404 };00405 00406 <span class="preprocessor">#endif // #ifndef NO_DOXYGEN // internal class -- do not document</span>00407 <span class="preprocessor"></span>00408 <span class="preprocessor">#endif</span>00409 <span class="preprocessor"></span></pre></div><hr><address style="align: right;"><small>Generated on Mon Jan 24 21:14:23 2005 for ZIG by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -