MINOR: h2: Let user of h2_recv() and h2_send() know xfer has been done.

Make h2_recv() and h2_send() return 1 if data has been sent/received, or 0
if it did not. That way the caller will be able to know if more work may
have to be done.
This commit is contained in:
Olivier Houchard 2018-08-17 18:39:46 +02:00 committed by Willy Tarreau
parent af4021e680
commit d4dd22d0ab

View File

@ -220,8 +220,8 @@ static const struct h2s *h2_idle_stream = &(const struct h2s){
}; };
static struct task *h2_timeout_task(struct task *t, void *context, unsigned short state); static struct task *h2_timeout_task(struct task *t, void *context, unsigned short state);
static void h2_send(struct h2c *h2c); static int h2_send(struct h2c *h2c);
static void h2_recv(struct h2c *h2c); static int h2_recv(struct h2c *h2c);
static struct task *h2_io_cb(struct task *t, void *ctx, unsigned short state); static struct task *h2_io_cb(struct task *t, void *ctx, unsigned short state);
static inline struct h2s *h2c_st_by_id(struct h2c *h2c, int id); static inline struct h2s *h2c_st_by_id(struct h2c *h2c, int id);
static int h2_frt_decode_headers(struct h2s *h2s); static int h2_frt_decode_headers(struct h2s *h2s);
@ -2234,22 +2234,22 @@ static int h2_process_mux(struct h2c *h2c)
/* Attempt to read data, and subscribe if none available */ /* Attempt to read data, and subscribe if none available */
static void h2_recv(struct h2c *h2c) static int h2_recv(struct h2c *h2c)
{ {
struct connection *conn = h2c->conn; struct connection *conn = h2c->conn;
struct buffer *buf; struct buffer *buf;
int max; int max;
if (h2c->wait_list.wait_reason & SUB_CAN_RECV) if (h2c->wait_list.wait_reason & SUB_CAN_RECV)
return; return 0;
if (!h2_recv_allowed(h2c)) if (!h2_recv_allowed(h2c))
return; return 0;
buf = h2_get_buf(h2c, &h2c->dbuf); buf = h2_get_buf(h2c, &h2c->dbuf);
if (!buf) { if (!buf) {
h2c->flags |= H2_CF_DEM_DALLOC; h2c->flags |= H2_CF_DEM_DALLOC;
return; return 0;
} }
max = buf->size - b_data(buf); max = buf->size - b_data(buf);
@ -2259,26 +2259,27 @@ static void h2_recv(struct h2c *h2c)
if (!b_data(buf)) { if (!b_data(buf)) {
conn->xprt->subscribe(conn, SUB_CAN_RECV, &h2c->wait_list); conn->xprt->subscribe(conn, SUB_CAN_RECV, &h2c->wait_list);
h2_release_buf(h2c, &h2c->dbuf); h2_release_buf(h2c, &h2c->dbuf);
return; return 0;
} }
if (b_data(buf) == buf->size) if (b_data(buf) == buf->size)
h2c->flags |= H2_CF_DEM_DFULL; h2c->flags |= H2_CF_DEM_DFULL;
return; return 1;
} }
/* Try to send data if possible */ /* Try to send data if possible */
static void h2_send(struct h2c *h2c) static int h2_send(struct h2c *h2c)
{ {
struct connection *conn = h2c->conn; struct connection *conn = h2c->conn;
int done; int done;
int sent = 0;
if (conn->flags & CO_FL_ERROR) if (conn->flags & CO_FL_ERROR)
return; return 0;
if (conn->flags & (CO_FL_HANDSHAKE|CO_FL_WAIT_L4_CONN|CO_FL_WAIT_L6_CONN)) { if (conn->flags & (CO_FL_HANDSHAKE|CO_FL_WAIT_L4_CONN|CO_FL_WAIT_L6_CONN)) {
/* a handshake was requested */ /* a handshake was requested */
return; goto schedule;
} }
/* This loop is quite simple : it tries to fill as much as it can from /* This loop is quite simple : it tries to fill as much as it can from
@ -2318,6 +2319,7 @@ static void h2_send(struct h2c *h2c)
int ret = conn->xprt->snd_buf(conn, &h2c->mbuf, b_data(&h2c->mbuf), flags); int ret = conn->xprt->snd_buf(conn, &h2c->mbuf, b_data(&h2c->mbuf), flags);
if (!ret) if (!ret)
break; break;
sent = 1;
b_del(&h2c->mbuf, ret); b_del(&h2c->mbuf, ret);
b_realign_if_empty(&h2c->mbuf); b_realign_if_empty(&h2c->mbuf);
} }
@ -2345,11 +2347,11 @@ static void h2_send(struct h2c *h2c)
} }
/* We're done, no more to send */ /* We're done, no more to send */
if (!b_data(&h2c->mbuf)) if (!b_data(&h2c->mbuf))
return; return sent;
schedule: schedule:
if (LIST_ISEMPTY(&h2c->wait_list.list)) if (LIST_ISEMPTY(&h2c->wait_list.list))
conn->xprt->subscribe(conn, SUB_CAN_SEND, &h2c->wait_list); conn->xprt->subscribe(conn, SUB_CAN_SEND, &h2c->wait_list);
return; return sent;
} }
static struct task *h2_io_cb(struct task *t, void *ctx, unsigned short status) static struct task *h2_io_cb(struct task *t, void *ctx, unsigned short status)