Browse Source

Send the last remaining send request without checking if it is ready for writes to avoid busy looping

master
Con Kolivas 11 years ago
parent
commit
4f1d13e922
  1. 35
      src/connector.c

35
src/connector.c

@ -310,8 +310,8 @@ void *sender(void *arg)
sender_send_t *sender_send; sender_send_t *sender_send;
client_instance_t *client; client_instance_t *client;
tv_t timeout_tv = {0, 0}; tv_t timeout_tv = {0, 0};
bool only_send = false;
int ret, fd, ofs = 0; int ret, fd, ofs = 0;
fd_set writefds;
mutex_lock(&sender_lock); mutex_lock(&sender_lock);
if (!sender_sends) { if (!sender_sends) {
@ -324,6 +324,8 @@ void *sender(void *arg)
sender_send = sender_sends; sender_send = sender_sends;
if (likely(sender_send)) if (likely(sender_send))
DL_DELETE(sender_sends, sender_send); DL_DELETE(sender_sends, sender_send);
if (!sender_send)
only_send = true;
mutex_unlock(&sender_lock); mutex_unlock(&sender_lock);
if (!sender_send) if (!sender_send)
@ -341,18 +343,25 @@ void *sender(void *arg)
free(sender_send); free(sender_send);
continue; continue;
} }
FD_ZERO(&writefds); /* If there are other sends pending and this socket is not
FD_SET(fd, &writefds); * ready to receive data from us, put the send back on the
ret = select(fd + 1, NULL, &writefds, NULL, &timeout_tv); * list. */
if (ret < 1) { if (!only_send) {
LOGDEBUG("Client %d not ready for writes", client->id); fd_set writefds;
/* Append it to the tail of the list */ FD_ZERO(&writefds);
mutex_lock(&sender_lock); FD_SET(fd, &writefds);
DL_APPEND(sender_sends, sender_send); ret = select(fd + 1, NULL, &writefds, NULL, &timeout_tv);
mutex_unlock(&sender_lock); if (ret < 1) {
LOGDEBUG("Client %d not ready for writes", client->id);
continue;
/* Append it to the tail of the list */
mutex_lock(&sender_lock);
DL_APPEND(sender_sends, sender_send);
mutex_unlock(&sender_lock);
continue;
}
} }
while (sender_send->len) { while (sender_send->len) {
ret = send(fd, sender_send->buf + ofs, sender_send->len , 0); ret = send(fd, sender_send->buf + ofs, sender_send->len , 0);

Loading…
Cancel
Save