mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 22:31:28 +02:00
MINOR: connection: add a new conn_drain() function
Till now there was no way to know from a connection if a previous call to drain() had done any change. This function is used to drain incoming data and to update the connection's flags at the same time. It also correctly sets the polling flags on the connection if the drain function indicates inability to receive. This function will be used preferably over ctrl->drain() when a connection is used.
This commit is contained in:
parent
7f4bcc312d
commit
2aefad5df7
@ -560,6 +560,40 @@ static inline void conn_attach(struct connection *conn, void *owner, const struc
|
||||
conn->owner = owner;
|
||||
}
|
||||
|
||||
/* Drains possibly pending incoming data on the file descriptor attached to the
|
||||
* connection and update the connection's flags accordingly. This is used to
|
||||
* know whether we need to disable lingering on close. Returns non-zero if it
|
||||
* is safe to close without disabling lingering, otherwise zero. The SOCK_RD_SH
|
||||
* flag may also be updated if the incoming shutdown was reported by the drain()
|
||||
* function.
|
||||
*/
|
||||
static inline int conn_drain(struct connection *conn)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!conn_ctrl_ready(conn))
|
||||
return 1;
|
||||
|
||||
if (conn->flags & CO_FL_SOCK_RD_SH)
|
||||
return 1;
|
||||
|
||||
if (conn->flags & CO_FL_WAIT_RD)
|
||||
return 0;
|
||||
|
||||
if (!conn->ctrl->drain)
|
||||
return 0;
|
||||
|
||||
ret = conn->ctrl->drain(conn->t.sock.fd);
|
||||
if (ret < 0)
|
||||
__conn_data_poll_recv(conn);
|
||||
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
|
||||
conn->flags |= CO_FL_SOCK_RD_SH;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* returns a human-readable error code for conn->err_code, or NULL if the code
|
||||
* is unknown.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user