mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 23:56:57 +02:00
[MEDIUM] third cleanup and optimization of process_srv_data()
Some repeated tests were factored out. Now the code makes sense and is fully understandable.
This commit is contained in:
parent
8fbd3b4ce7
commit
2ac679d9aa
@ -3900,57 +3900,46 @@ int process_srv_data(struct session *t)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if we need to close the read side */
|
||||
if (!(rep->flags & BF_SHUTR)) {
|
||||
/* Last read, forced read-shutdown, or other end closed */
|
||||
if (!(rep->flags & BF_SHUTR) &&
|
||||
rep->flags & (BF_READ_NULL|BF_SHUTR_NOW|BF_SHUTW)) {
|
||||
if (rep->flags & (BF_READ_NULL|BF_SHUTR_NOW|BF_SHUTW)) {
|
||||
trace_term(t, TT_HTTP_SRV_10);
|
||||
do_close_read:
|
||||
buffer_shutr(rep);
|
||||
if (req->flags & BF_SHUTW)
|
||||
goto do_close_and_return;
|
||||
|
||||
EV_FD_CLR(fd, DIR_RD);
|
||||
}
|
||||
|
||||
/* Forced write-shutdown or other end closed with empty buffer.
|
||||
* We have to forward the shutdown request if allowed to.
|
||||
*/
|
||||
if (!(req->flags & BF_SHUTW) && /* not already done */
|
||||
(req->flags & BF_SHUTW_NOW ||
|
||||
(req->flags & (BF_EMPTY|BF_MAY_FORWARD|BF_SHUTR)) == (BF_EMPTY|BF_MAY_FORWARD|BF_SHUTR))) {
|
||||
trace_term(t, TT_HTTP_SRV_11);
|
||||
buffer_shutw(req);
|
||||
if (rep->flags & BF_SHUTR)
|
||||
goto do_close_and_return;
|
||||
|
||||
EV_FD_CLR(fd, DIR_WR);
|
||||
shutdown(fd, SHUT_WR);
|
||||
}
|
||||
|
||||
/* Read timeout */
|
||||
if (unlikely((rep->flags & (BF_SHUTR|BF_READ_TIMEOUT)) == 0 &&
|
||||
tick_is_expired(rep->rex, now_ms))) {
|
||||
else if (unlikely(!(rep->flags & BF_READ_TIMEOUT) && tick_is_expired(rep->rex, now_ms))) {
|
||||
trace_term(t, TT_HTTP_SRV_12);
|
||||
rep->flags |= BF_READ_TIMEOUT;
|
||||
if (!req->cons->err_type) {
|
||||
req->cons->err_loc = t->srv;
|
||||
req->cons->err_type = SI_ET_DATA_TO;
|
||||
}
|
||||
buffer_shutr(rep);
|
||||
if (req->flags & BF_SHUTW)
|
||||
goto do_close_and_return;
|
||||
|
||||
EV_FD_CLR(fd, DIR_RD);
|
||||
goto do_close_read;
|
||||
}
|
||||
/* Read not closed, update FD status and timeout for reads */
|
||||
else if (rep->flags & (BF_FULL|BF_HIJACK)) {
|
||||
if (EV_FD_COND_C(fd, DIR_RD))
|
||||
rep->rex = TICK_ETERNITY;
|
||||
}
|
||||
else {
|
||||
EV_FD_COND_S(fd, DIR_RD);
|
||||
rep->rex = tick_add_ifset(now_ms, rep->rto);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write timeout */
|
||||
if (unlikely((req->flags & (BF_SHUTW|BF_WRITE_TIMEOUT)) == 0 &&
|
||||
tick_is_expired(req->wex, now_ms))) {
|
||||
trace_term(t, TT_HTTP_SRV_13);
|
||||
req->flags |= BF_WRITE_TIMEOUT;
|
||||
if (!req->cons->err_type) {
|
||||
req->cons->err_loc = t->srv;
|
||||
req->cons->err_type = SI_ET_DATA_TO;
|
||||
}
|
||||
/* Check if we need to close the write side */
|
||||
if (!(req->flags & BF_SHUTW)) {
|
||||
/* Forced write-shutdown or other end closed with empty buffer. */
|
||||
if ((req->flags & BF_SHUTW_NOW) ||
|
||||
(req->flags & (BF_EMPTY|BF_MAY_FORWARD|BF_SHUTR)) == (BF_EMPTY|BF_MAY_FORWARD|BF_SHUTR)) {
|
||||
trace_term(t, TT_HTTP_SRV_11);
|
||||
do_close_write:
|
||||
buffer_shutw(req);
|
||||
if (rep->flags & BF_SHUTR)
|
||||
goto do_close_and_return;
|
||||
@ -3958,25 +3947,23 @@ int process_srv_data(struct session *t)
|
||||
EV_FD_CLR(fd, DIR_WR);
|
||||
shutdown(fd, SHUT_WR);
|
||||
}
|
||||
|
||||
/* Update FD status and timeout for reads */
|
||||
if (!(rep->flags & BF_SHUTR)) {
|
||||
if (rep->flags & (BF_FULL|BF_HIJACK)) {
|
||||
if (EV_FD_COND_C(fd, DIR_RD))
|
||||
rep->rex = TICK_ETERNITY;
|
||||
} else {
|
||||
EV_FD_COND_S(fd, DIR_RD);
|
||||
rep->rex = tick_add_ifset(now_ms, rep->rto);
|
||||
/* Write timeout */
|
||||
else if (unlikely(!(req->flags & BF_WRITE_TIMEOUT) && tick_is_expired(req->wex, now_ms))) {
|
||||
trace_term(t, TT_HTTP_SRV_13);
|
||||
req->flags |= BF_WRITE_TIMEOUT;
|
||||
if (!req->cons->err_type) {
|
||||
req->cons->err_loc = t->srv;
|
||||
req->cons->err_type = SI_ET_DATA_TO;
|
||||
}
|
||||
goto do_close_write;
|
||||
}
|
||||
|
||||
/* Update FD status and timeout for writes */
|
||||
if (!(req->flags & BF_SHUTW)) {
|
||||
if ((req->flags & (BF_EMPTY|BF_MAY_FORWARD)) != BF_MAY_FORWARD) {
|
||||
/* Write not closed, update FD status and timeout for writes */
|
||||
else if ((req->flags & (BF_EMPTY|BF_MAY_FORWARD)) != BF_MAY_FORWARD) {
|
||||
/* stop writing */
|
||||
if (EV_FD_COND_C(fd, DIR_WR))
|
||||
req->wex = TICK_ETERNITY;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* buffer not empty, there are still data to be transferred */
|
||||
EV_FD_COND_S(fd, DIR_WR);
|
||||
if (!tick_isset(req->wex)) {
|
||||
|
Loading…
Reference in New Issue
Block a user