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; buf = out_buf;
pthread_mutex_unlock(&buf_lock); pthread_mutex_unlock(&buf_lock);
len = write(fd, buf.c_str(), buf.size()); if (buf.size() > 0) {
if (len < 0) { len = write(fd, buf.c_str(), buf.size());
pthread_mutex_lock(&cancel_lock); if (len < 0) {
error = true; pthread_mutex_lock(&cancel_lock);
} else { error = true;
pthread_mutex_lock(&buf_lock); } else {
out_buf.erase(0, len); pthread_mutex_lock(&buf_lock);
pthread_mutex_unlock(&buf_lock); out_buf.erase(0, len);
pthread_mutex_unlock(&buf_lock);
}
} }
struct timeval tv; struct timeval tv;