]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add a new conn_drain() function
authorWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2014 10:41:52 +0000 (11:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 20 Jan 2014 21:27:16 +0000 (22:27 +0100)
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.

include/proto/connection.h

index e172cfe78ad4a1fe0d0eea2b15d5683a58806dce..7c969eb4cb4c56b3832d56a1773f3225b51ff203 100644 (file)
@@ -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.
  */