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.18 by root, Thu Dec 14 05:09:32 2006 UTC vs.
Revision 1.19 by root, Thu Dec 14 20:39:54 2006 UTC

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
381client_socket::send_packet (packet &sl) 387client_socket::send_packet (packet &sl)
382{ 388{
383 Send_With_Handling (this, &sl);
384}
385
386void
387client_socket::send_packet (const char *buf, int len)
388{
389 packet sl;
390
391 sl << data (buf, len);
392 send_packet (sl);
393}
394
395void
396client_socket::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 (client_socket *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 //TODO: single write, or writev 404 assert (sl.hdrlen == 2);
428 ns->send (sbuf, 2); 405
429 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));
430} 425}
431 426
432/****************************************************************************** 427/******************************************************************************
433 * 428 *
434 * statistics logging functions. 429 * statistics logging functions.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines