… | |
… | |
370 | cst_lst.obytes += amt; |
370 | cst_lst.obytes += amt; |
371 | #endif |
371 | #endif |
372 | } |
372 | } |
373 | } |
373 | } |
374 | |
374 | |
|
|
375 | void |
|
|
376 | client_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 | |
|
|
380 | void |
386 | void |
381 | client_socket::send_packet (packet &sl) |
387 | client_socket::send_packet (packet &sl) |
382 | { |
388 | { |
383 | Send_With_Handling (this, &sl); |
|
|
384 | } |
|
|
385 | |
|
|
386 | void |
|
|
387 | client_socket::send_packet (const char *buf, int len) |
|
|
388 | { |
|
|
389 | packet sl; |
|
|
390 | |
|
|
391 | sl << data (buf, len); |
|
|
392 | send_packet (sl); |
|
|
393 | } |
|
|
394 | |
|
|
395 | void |
|
|
396 | client_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 | */ |
|
|
407 | void |
|
|
408 | Send_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 | 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 | |
|
|
412 | void |
|
|
413 | client_socket::send_packet (const char *buf, int len) |
|
|
414 | { |
|
|
415 | packet sl; |
|
|
416 | |
|
|
417 | sl << data (buf, len); |
|
|
418 | send_packet (sl); |
|
|
419 | } |
|
|
420 | |
|
|
421 | void |
|
|
422 | client_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 | |