/* send_linebuf() * * inputs - client to send to, linebuf to attach * outputs - * side effects - linebuf is attached to client */ static int _send_linebuf(struct Client *to, buf_head_t *linebuf) { if(IsMe(to)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Trying to send message to myself!"); return 0; } if(!MyConnect(to) || IsIOError(to)) return 0; if(linebuf_len(&to->localClient->buf_sendq) > get_sendq(to)) { if(IsServer(to)) { sendto_realops_snomask(SNO_GENERAL, L_ALL, "Max SendQ limit exceeded for %s: %u > %lu", get_server_name(to, HIDE_IP), linebuf_len(&to->localClient->buf_sendq), get_sendq(to)); ilog(L_SERVER, "Max SendQ limit exceeded for %s: %u > %lu", log_client_name(to, SHOW_IP), linebuf_len(&to->localClient->buf_sendq), get_sendq(to)); } if(IsClient(to)) to->flags |= FLAGS_SENDQEX; dead_link(to); return -1; } else { /* just attach the linebuf to the sendq instead of * generating a new one */ linebuf_attach(&to->localClient->buf_sendq, linebuf); } /* ** Update statistics. The following is slightly incorrect ** because it counts messages even if queued, but bytes ** only really sent. Queued bytes get updated in SendQueued. */ to->localClient->sendM += 1; me.localClient->sendM += 1; if(linebuf_len(&to->localClient->buf_sendq) > 0) send_queued_write(to->localClient->fd, to); return 0; }
/* send_queued_write() * * inputs - fd to have queue sent, client we're sending to * outputs - contents of queue * side effects - write is rescheduled if queue isnt emptied */ void send_queued_write(int fd, void *data) { struct Client *to = data; int retlen; int flags; #ifdef USE_IODEBUG_HOOKS hook_data_int hd; #endif /* cant write anything to a dead socket. */ if(IsIOError(to)) return; #ifdef USE_IODEBUG_HOOKS hd.client = to; if(to->localClient->buf_sendq.list.head) hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head->data)->buf + to->localClient->buf_sendq.writeofs; #endif if(linebuf_len(&to->localClient->buf_sendq)) { while ((retlen = linebuf_flush(to->localClient->fd, &to->localClient->buf_sendq)) > 0) { /* We have some data written .. update counters */ #ifdef USE_IODEBUG_HOOKS hd.arg2 = retlen; call_hook(h_iosend_id, &hd); if(to->localClient->buf_sendq.list.head) hd.arg1 = ((buf_line_t *) to->localClient->buf_sendq.list.head-> data)->buf + to->localClient->buf_sendq.writeofs; #endif to->localClient->sendB += retlen; me.localClient->sendB += retlen; if(to->localClient->sendB > 1023) { to->localClient->sendK += (to->localClient->sendB >> 10); to->localClient->sendB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ } else if(me.localClient->sendB > 1023) { me.localClient->sendK += (me.localClient->sendB >> 10); me.localClient->sendB &= 0x03ff; }