mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
connection::thread_loop(): Do not write() if we have nothing to write
This commit is contained in:
parent
296f4148d3
commit
f6221436a4
1 changed files with 10 additions and 8 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue