tcp_splice: Exploit side symmetry in tcp_splice_timer()
tcp_splice_timer() has two very similar blocks one after another that handle the SO_RCVLOWAT flags for the two sides of the connection. We can deduplicate this with a loop across the two sides. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
8545058fbe
commit
1b76257147
1 changed files with 11 additions and 16 deletions
27
tcp_splice.c
27
tcp_splice.c
|
@ -835,30 +835,25 @@ void tcp_splice_init(struct ctx *c)
|
||||||
void tcp_splice_timer(struct ctx *c, union tcp_conn *conn_union)
|
void tcp_splice_timer(struct ctx *c, union tcp_conn *conn_union)
|
||||||
{
|
{
|
||||||
struct tcp_splice_conn *conn = &conn_union->splice;
|
struct tcp_splice_conn *conn = &conn_union->splice;
|
||||||
|
int side;
|
||||||
|
|
||||||
if (conn->flags & CLOSING) {
|
if (conn->flags & CLOSING) {
|
||||||
tcp_splice_destroy(c, conn_union);
|
tcp_splice_destroy(c, conn_union);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (conn->flags & RCVLOWAT_SET_0) &&
|
for (side = 0; side < SIDES; side++) {
|
||||||
!(conn->flags & RCVLOWAT_ACT_0)) {
|
uint8_t set = side == 0 ? RCVLOWAT_SET_0 : RCVLOWAT_SET_1;
|
||||||
if (setsockopt(conn->s[0], SOL_SOCKET, SO_RCVLOWAT,
|
uint8_t act = side == 0 ? RCVLOWAT_ACT_0 : RCVLOWAT_ACT_1;
|
||||||
&((int){ 1 }), sizeof(int))) {
|
|
||||||
trace("TCP (spliced): can't set SO_RCVLOWAT on "
|
|
||||||
"%i", conn->s[0]);
|
|
||||||
}
|
|
||||||
conn_flag(c, conn, ~RCVLOWAT_SET_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (conn->flags & RCVLOWAT_SET_1) &&
|
if ((conn->flags & set) && !(conn->flags & act)) {
|
||||||
!(conn->flags & RCVLOWAT_ACT_1)) {
|
if (setsockopt(conn->s[side], SOL_SOCKET, SO_RCVLOWAT,
|
||||||
if (setsockopt(conn->s[1], SOL_SOCKET, SO_RCVLOWAT,
|
&((int){ 1 }), sizeof(int))) {
|
||||||
&((int){ 1 }), sizeof(int))) {
|
trace("TCP (spliced): can't set SO_RCVLOWAT on "
|
||||||
trace("TCP (spliced): can't set SO_RCVLOWAT on "
|
"%i", conn->s[side]);
|
||||||
"%i", conn->s[1]);
|
}
|
||||||
|
conn_flag(c, conn, ~set);
|
||||||
}
|
}
|
||||||
conn_flag(c, conn, ~RCVLOWAT_SET_1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
conn_flag(c, conn, ~RCVLOWAT_ACT_0);
|
conn_flag(c, conn, ~RCVLOWAT_ACT_0);
|
||||||
|
|
Loading…
Reference in a new issue