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. 11
      src/connector.c

11
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,6 +343,12 @@ void *sender(void *arg)
free(sender_send); free(sender_send);
continue; 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) {
fd_set writefds;
FD_ZERO(&writefds); FD_ZERO(&writefds);
FD_SET(fd, &writefds); FD_SET(fd, &writefds);
ret = select(fd + 1, NULL, &writefds, NULL, &timeout_tv); ret = select(fd + 1, NULL, &writefds, NULL, &timeout_tv);
@ -354,6 +362,7 @@ void *sender(void *arg)
continue; 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);
if (unlikely(ret < 0)) { if (unlikely(ret < 0)) {

Loading…
Cancel
Save