connection::thread_loop(): Do not write() if we have nothing to write

This commit is contained in:
Petr Baudis 2011-11-27 02:40:57 +01:00
parent 296f4148d3
commit f6221436a4

View file

@ -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;