ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/lowlevel.C
(Generate patch)

Comparing deliantra/server/socket/lowlevel.C (file contents):
Revision 1.15 by root, Thu Dec 14 01:59:10 2006 UTC vs.
Revision 1.19 by root, Thu Dec 14 20:39:54 2006 UTC

51// easily die in 20 seconds... 51// easily die in 20 seconds...
52#define SOCKET_TIMEOUT1 10 52#define SOCKET_TIMEOUT1 10
53#define SOCKET_TIMEOUT2 20 53#define SOCKET_TIMEOUT2 20
54 54
55void 55void
56Socket_Flush (NewSocket * ns) 56Socket_Flush (client_socket * ns)
57{ 57{
58#ifdef __linux__ 58#ifdef __linux__
59 // check time of last ack, and, if too old, kill connection 59 // check time of last ack, and, if too old, kill connection
60 struct tcp_info tcpi; 60 struct tcp_info tcpi;
61 socklen_t len = sizeof (tcpi); 61 socklen_t len = sizeof (tcpi);
140 * Start of read routines. 140 * Start of read routines.
141 * 141 *
142 ******************************************************************************/ 142 ******************************************************************************/
143 143
144int 144int
145NewSocket::read_packet () 145client_socket::read_packet ()
146{ 146{
147 for (;;) 147 for (;;)
148 { 148 {
149 if (inbuf_len >= 2) 149 if (inbuf_len >= 2)
150 { 150 {
186 cst_lst.ibytes += amount; 186 cst_lst.ibytes += amount;
187 } 187 }
188} 188}
189 189
190void 190void
191NewSocket::skip_packet (int len) 191client_socket::skip_packet (int len)
192{ 192{
193 inbuf_len -= len; 193 inbuf_len -= len;
194 memmove (inbuf, inbuf + len, inbuf_len); 194 memmove (inbuf, inbuf + len, inbuf_len);
195} 195}
196 196
206 * ns is the socket we are adding the data to, buf is the start of the 206 * ns is the socket we are adding the data to, buf is the start of the
207 * data, and len is the number of bytes to add. 207 * data, and len is the number of bytes to add.
208 */ 208 */
209 209
210static void 210static void
211add_to_buffer (NewSocket *ns, char *buf, int len) 211add_to_buffer (client_socket *ns, char *buf, int len)
212{ 212{
213 int avail, end; 213 int avail, end;
214 214
215 if ((len + ns->outputbuffer.len) > SOCKETBUFSIZE) 215 if ((len + ns->outputbuffer.len) > SOCKETBUFSIZE)
216 { 216 {
250 * 250 *
251 * When the socket is clear to write, and we have backlogged data, this 251 * When the socket is clear to write, and we have backlogged data, this
252 * is called to write it out. 252 * is called to write it out.
253 */ 253 */
254void 254void
255write_socket_buffer (NewSocket * ns) 255write_socket_buffer (client_socket * ns)
256{ 256{
257 int amt, max; 257 int amt, max;
258 258
259 if (ns->outputbuffer.len == 0) 259 if (ns->outputbuffer.len == 0)
260 { 260 {
309 * provided (ns). buf is the data to write, len is the number 309 * provided (ns). buf is the data to write, len is the number
310 * of bytes to write. IT doesn't return anything - rather, it 310 * of bytes to write. IT doesn't return anything - rather, it
311 * updates the ns structure if we get an error. 311 * updates the ns structure if we get an error.
312 */ 312 */
313void 313void
314NewSocket::send (void *buf_, int len) 314client_socket::send (void *buf_, int len)
315{ 315{
316 char *buf = (char *)buf_; 316 char *buf = (char *)buf_;
317 char *pos = buf; 317 char *pos = buf;
318 int amt = 0; 318 int amt = 0;
319 319
370 cst_lst.obytes += amt; 370 cst_lst.obytes += amt;
371#endif 371#endif
372 } 372 }
373} 373}
374 374
375void
376client_socket::socket_cb (iow &w, int got)
377{
378 //printf ("iow got %x\n", got);
379 w.stop ();
380}
381
375/** 382/**
376 * Takes a string of data, and writes it out to the socket. A very handy 383 * Takes a string of data, and writes it out to the socket. A very handy
377 * shortcut function. 384 * shortcut function.
378 */ 385 */
379
380void 386void
381NewSocket::send_packet (packet &sl) 387client_socket::send_packet (packet &sl)
382{ 388{
383 Send_With_Handling (this, &sl);
384}
385
386void
387NewSocket::send_packet (const char *buf, int len)
388{
389 packet sl;
390
391 sl << data (buf, len);
392 send_packet (sl);
393}
394
395void
396NewSocket::send_packet (const char *buf)
397{
398 send_packet (buf, strlen (buf));
399}
400
401/**
402 * Calls Write_To_Socket to send data to the client.
403 *
404 * The only difference in this function is that we take a packet
405 *, and we prepend the length information.
406 */
407void
408Send_With_Handling (NewSocket *ns, packet *msg)
409{
410 unsigned char sbuf[4];
411
412 if (ns->status == Ns_Dead || !msg) 389 if (status == Ns_Dead)
413 return; 390 return;
414 391
415 if (msg->length () >= MAXSOCKBUF) 392 if (sl.length () >= MAXSOCKBUF)
416 { 393 {
417 LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", msg->length ()); 394 LOG (llevError, "Trying to send a buffer beyond properly size, len =%d\n", sl.length ());
418 /* Almost certainly we've overflowed a buffer, so quite now to make 395 /* Almost certainly we've overflowed a buffer, so quit now to make
419 * it easier to debug. 396 * it easier to debug.
420 */ 397 */
421 abort (); 398 abort ();
422 } 399 }
423 400
424 sbuf[0] = ((uint32) (msg->length ()) >> 8); 401 if (!sl.length ())
425 sbuf[1] = ((uint32) (msg->length ()) ); 402 return;
426 403
427 if (ns->status != Ns_Old) 404 assert (sl.hdrlen == 2);
428 ns->send (sbuf, 2);
429 405
430 ns->send (msg->buf, msg->length ()); 406 sl.buf_ [0] = sl.length () >> 8;
407 sl.buf_ [1] = sl.length () ;
408
409 send (sl.buf_, sl.length () + sl.hdrlen);
410}
411
412void
413client_socket::send_packet (const char *buf, int len)
414{
415 packet sl;
416
417 sl << data (buf, len);
418 send_packet (sl);
419}
420
421void
422client_socket::send_packet (const char *buf)
423{
424 send_packet (buf, strlen (buf));
431} 425}
432 426
433/****************************************************************************** 427/******************************************************************************
434 * 428 *
435 * statistics logging functions. 429 * statistics logging functions.
459 LOG (llevInfo, "CSSTAT: %.16s tot %d %d %d %d inc %d %d %d %d\n", 453 LOG (llevInfo, "CSSTAT: %.16s tot %d %d %d %d inc %d %d %d %d\n",
460 ctime (&now), cst_tot.ibytes, cst_tot.obytes, cst_tot.max_conn, 454 ctime (&now), cst_tot.ibytes, cst_tot.obytes, cst_tot.max_conn,
461 now - cst_tot.time_start, cst_lst.ibytes, cst_lst.obytes, cst_lst.max_conn, now - cst_lst.time_start); 455 now - cst_tot.time_start, cst_lst.ibytes, cst_lst.obytes, cst_lst.max_conn, now - cst_lst.time_start);
462 cst_lst.ibytes = 0; 456 cst_lst.ibytes = 0;
463 cst_lst.obytes = 0; 457 cst_lst.obytes = 0;
464 cst_lst.max_conn = socket_info.nconns;
465 cst_lst.time_start = now; 458 cst_lst.time_start = now;
466} 459}
467#endif 460#endif
468 461

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines