From f6221436a48c7a265bc164fbd2e6cffec2161988 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 27 Nov 2011 02:40:57 +0100 Subject: [PATCH] connection::thread_loop(): Do not write() if we have nothing to write --- connection.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/connection.cc b/connection.cc index 9bdc3dd..f54cb41 100644 --- a/connection.cc +++ b/connection.cc @@ -94,14 +94,16 @@ connection::thread_loop(void) buf = out_buf; pthread_mutex_unlock(&buf_lock); - len = write(fd, buf.c_str(), buf.size()); - if (len < 0) { - pthread_mutex_lock(&cancel_lock); - error = true; - } else { - pthread_mutex_lock(&buf_lock); - out_buf.erase(0, len); - pthread_mutex_unlock(&buf_lock); + if (buf.size() > 0) { + len = write(fd, buf.c_str(), buf.size()); + if (len < 0) { + pthread_mutex_lock(&cancel_lock); + error = true; + } else { + pthread_mutex_lock(&buf_lock); + out_buf.erase(0, len); + pthread_mutex_unlock(&buf_lock); + } } struct timeval tv;