| 354 | } |
| 355 | |
| 356 | int tcp_write_on_socket(struct tcp_connection* c, int fd, |
| 357 | char *buf, int len, int write_timeout, int async_write_timeout) |
| 358 | { |
| 359 | int n; |
| 360 | |
| 361 | lock_get(&c->write_lock); |
| 362 | if (fd < 0) { |
| 363 | n = tcp_async_add_chunk(c, buf, len, 0); |
| 364 | if (n == 0) |
| 365 | n = len; |
| 366 | } else if (c->async) { |
| 367 | /* |
| 368 | * if there is any data pending to write, we have to wait for those chunks |
| 369 | * to be sent, otherwise we will completely break the messages' order |
| 370 | */ |
| 371 | if (c->async->pending) |
| 372 | n = tcp_async_add_chunk(c, buf, len, 0); |
| 373 | else |
| 374 | n = tsend_stream_async(c,fd,buf,len, async_write_timeout); |
| 375 | } else { |
| 376 | n = tsend_stream(fd, buf, len, write_timeout); |
| 377 | } |
| 378 | lock_release(&c->write_lock); |
| 379 | if (fd >= 0 && n > 0) |
| 380 | tcp_conn_reset_lifetime(c); |
| 381 | |
| 382 | return n; |
| 383 | } |
| 384 | |
| 385 | /* returns : |
| 386 | * 0 - in case of success |
no test coverage detected