| 392 | } |
| 393 | |
| 394 | static int tcp_drain(struct tcp_connection *c, char *buf, int len) |
| 395 | { |
| 396 | int bytes_read, total = 0; |
| 397 | int retries = 0; |
| 398 | int fd = c->fd; |
| 399 | again: |
| 400 | bytes_read = read(fd, buf + total, len - total); |
| 401 | if (bytes_read < 0) { |
| 402 | if (errno == EINTR) { |
| 403 | goto again; |
| 404 | } else if (errno == EAGAIN || errno == EWOULDBLOCK) { |
| 405 | if (++retries > 100) { |
| 406 | LM_ERR("failed consuming proxy_protocol header due to repeated EAGAIN\n"); |
| 407 | return -1; |
| 408 | } |
| 409 | goto again; |
| 410 | } else { |
| 411 | LM_ERR("error consuming proxy_protocol header: %s\n", strerror(errno)); |
| 412 | return -1; |
| 413 | } |
| 414 | } else if (bytes_read == 0) { |
| 415 | c->state = S_CONN_EOF; |
| 416 | LM_DBG("EOF on %p, FD %d while consuming proxy_protocol header\n", c, fd); |
| 417 | return -1; |
| 418 | } |
| 419 | total += bytes_read; |
| 420 | retries = 0; |
| 421 | if (total < len) |
| 422 | goto again; |
| 423 | |
| 424 | return total; |
| 425 | } |
| 426 | |
| 427 | int check_tcp_proxy_protocol(struct tcp_connection *c) |
| 428 | { |
no outgoing calls
no test coverage detected