MINOR: channel: don't use co_set_data() to decrement output

The use of co_set_data() should be strictly limited to setting the amount
of existing data to be transmitted. It ought not be used to decrement the
output after the data have left the buffer, because doing so involves
performing incorrect calculations using co_data() that still comprises
data that are not in the buffer anymore. Let's use c_rew() for this, which
is made exactly for this purpose, i.e. decrement c->output by as much as
requested. This is cleaner, faster, and will permit stricter checks.
This commit is contained in:
Willy Tarreau 2022-02-28 16:51:23 +01:00
parent 8873b85bd9
commit 84240044f0
3 changed files with 4 additions and 4 deletions

View File

@ -1007,7 +1007,7 @@ static inline int32_t co_htx_remove_blk(struct channel *chn, struct htx *htx, st
int32_t size = htx_get_blksz(blk);
htx_remove_blk(htx, blk);
co_set_data(chn, co_data(chn) - size);
c_rew(chn, size);
return size;
}

View File

@ -4991,7 +4991,7 @@ __LJMP static int hlua_applet_http_getline_yield(lua_State *L, int status, lua_K
break;
}
co_set_data(req, co_data(req) - vlen);
c_rew(req, vlen);
count -= vlen;
if (sz == vlen)
blk = htx_remove_blk(htx, blk);
@ -5081,7 +5081,7 @@ __LJMP static int hlua_applet_http_recv_yield(lua_State *L, int status, lua_KCon
break;
}
co_set_data(req, co_data(req) - vlen);
c_rew(req, vlen);
count -= vlen;
if (len > 0)
len -= vlen;

View File

@ -792,7 +792,7 @@ int si_cs_send(struct conn_stream *cs)
ret = conn->mux->snd_buf(cs, &oc->buf, co_data(oc), send_flag);
if (ret > 0) {
did_send = 1;
co_set_data(oc, co_data(oc) - ret);
c_rew(oc, ret);
c_realign_if_empty(oc);
if (!co_data(oc)) {