Browse Source

Poll more frequently when a client is not ready to be written to instead of waiting for it

master
Con Kolivas 10 years ago
parent
commit
f564714345
  1. 20
      src/connector.c

20
src/connector.c

@ -326,13 +326,13 @@ void *sender(void *arg)
{
conn_instance_t *ci = (conn_instance_t *)arg;
ckpool_t *ckp = ci->pi->ckp;
bool polling = false;
rename_proc("csender");
while (42) {
sender_send_t *sender_send;
client_instance_t *client;
bool only_send = false;
int ret, fd, ofs = 0;
mutex_lock(&sender_lock);
@ -340,14 +340,17 @@ void *sender(void *arg)
ts_t timeout_ts;
ts_realtime(&timeout_ts);
if (!polling)
timeout_ts.tv_sec += 1;
else {
ts_t wait_ts = {0, 1000000};
timeraddspec(&timeout_ts, &wait_ts);
}
pthread_cond_timedwait(&sender_cond, &sender_lock, &timeout_ts);
}
sender_send = sender_sends;
if (likely(sender_send))
DL_DELETE(sender_sends, sender_send);
if (!sender_send)
only_send = true;
mutex_unlock(&sender_lock);
if (!sender_send)
@ -365,10 +368,10 @@ void *sender(void *arg)
free(sender_send);
continue;
}
/* If there are other sends pending and this socket is not
* ready to receive data from us, put the send back on the
* list. */
if (!only_send) {
/* If this socket is not ready to receive data from us, put the
* send back on the tail of the list and decrease the timeout
* to poll to either look for a client that is ready or poll
* select on this one */
ret = wait_write_select(fd, 0);
if (ret < 1) {
LOGDEBUG("Client %d not ready for writes", client->id);
@ -378,9 +381,10 @@ void *sender(void *arg)
DL_APPEND(sender_sends, sender_send);
mutex_unlock(&sender_lock);
polling = true;
continue;
}
}
polling = false;
while (sender_send->len) {
ret = send(fd, sender_send->buf + ofs, sender_send->len , 0);
if (unlikely(ret < 0)) {

Loading…
Cancel
Save