]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: add simple functions to report connection readiness
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Dec 2013 09:23:20 +0000 (10:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 16 Dec 2013 01:23:52 +0000 (02:23 +0100)
conn_xprt_ready() reports if the transport layer is ready.
conn_ctrl_ready() reports if the control layer is ready.

The stream interface uses si_conn_ready() to report that the
underlying connection is ready. This will be used for connection
reuse in keep-alive mode.

include/proto/connection.h
include/proto/stream_interface.h
src/stream_interface.c

index a642960710b6d7826262ed2402fcf5ca70780a37..a36906d18b395fdf8fa684e3dde5d135f572355b 100644 (file)
@@ -43,6 +43,18 @@ int conn_fd_handler(int fd);
 int conn_recv_proxy(struct connection *conn, int flag);
 int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst);
 
+/* returns true is the transport layer is ready */
+static inline int conn_xprt_ready(struct connection *conn)
+{
+       return (conn->flags & CO_FL_XPRT_READY) && conn->xprt;
+}
+
+/* returns true is the control layer is ready */
+static inline int conn_ctrl_ready(struct connection *conn)
+{
+       return (conn->flags & CO_FL_CTRL_READY);
+}
+
 /* Calls the init() function of the transport layer if any and if not done yet,
  * and sets the CO_FL_XPRT_READY flag to indicate it was properly initialized.
  * Returns <0 in case of error.
index 7ab72ce7ac0323316798d7a1d2450fc5a7c87b2c..5408f1e05250003d0b775c81c6991885e730ef89 100644 (file)
@@ -149,6 +149,16 @@ static inline void si_attach_conn(struct stream_interface *si, struct connection
        conn_attach(conn, si, &si_conn_cb);
 }
 
+/* Returns true if a connection is attached to the stream interface <si> and
+ * if this connection is ready.
+ */
+static inline int si_conn_ready(struct stream_interface *si)
+{
+       struct connection *conn = objt_conn(si->end);
+
+       return conn && conn_ctrl_ready(conn) && conn_xprt_ready(conn);
+}
+
 /* Attach appctx <appctx> to the stream interface <si>. The stream interface
  * is configured to work with an applet context. It is left to the caller to
  * call appctx_set_applet() to assign an applet to this context.
index 34438d7e3e7e1bc070afa22f8f8ca40f476e7b4b..f2650d3647ff773276c23855bad7bd186cd37519 100644 (file)
@@ -389,7 +389,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
        if (conn->flags & CO_FL_SOCK_WR_SH)
                goto out_error;
 
-       if (!(conn->flags & CO_FL_CTRL_READY))
+       if (!conn_ctrl_ready(conn))
                goto out_error;
 
        /* If we have a PROXY line to send, we'll use this to validate the
@@ -812,7 +812,7 @@ static void stream_int_shutw_conn(struct stream_interface *si)
                        /* quick close, the socket is alredy shut anyway */
                }
                else if (si->flags & SI_FL_NOLINGER) {
-                       if ((conn->flags & CO_FL_CTRL_READY) && conn->ctrl) {
+                       if (conn_ctrl_ready(conn)) {
                                setsockopt(conn->t.sock.fd, SOL_SOCKET, SO_LINGER,
                                           (struct linger *) &nolinger, sizeof(struct linger));
                        }
@@ -833,7 +833,7 @@ static void stream_int_shutw_conn(struct stream_interface *si)
                         */
                        if (!(si->flags & SI_FL_NOHALF) || !(si->ib->flags & (CF_SHUTR|CF_DONT_READ))) {
                                /* We shutdown transport layer */
-                               if ((conn->flags & CO_FL_CTRL_READY) && conn->ctrl)
+                               if (conn_ctrl_ready(conn))
                                        shutdown(conn->t.sock.fd, SHUT_WR);
 
                                if (!(si->ib->flags & (CF_SHUTR|CF_DONT_READ))) {
@@ -931,13 +931,13 @@ static void stream_int_chk_snd_conn(struct stream_interface *si)
                /* Before calling the data-level operations, we have to prepare
                 * the polling flags to ensure we properly detect changes.
                 */
-               if ((conn->flags & CO_FL_CTRL_READY) && conn->ctrl)
+               if (conn_ctrl_ready(conn))
                        fd_want_send(conn->t.sock.fd);
 
                conn_refresh_polling_flags(conn);
 
                si_conn_send(conn);
-               if ((conn->flags & CO_FL_CTRL_READY) && (conn->flags & CO_FL_ERROR)) {
+               if (conn_ctrl_ready(conn) && (conn->flags & CO_FL_ERROR)) {
                        /* Write error on the file descriptor */
                        fd_stop_both(conn->t.sock.fd);
                        __conn_data_stop_both(conn);
@@ -1287,7 +1287,7 @@ void stream_sock_read0(struct stream_interface *si)
                /* we want to immediately forward this close to the write side */
                if (si->flags & SI_FL_NOLINGER) {
                        si->flags &= ~SI_FL_NOLINGER;
-                       if (conn->flags & CO_FL_CTRL_READY)
+                       if (conn_ctrl_ready(conn))
                                setsockopt(conn->t.sock.fd, SOL_SOCKET, SO_LINGER,
                                           (struct linger *) &nolinger, sizeof(struct linger));
                }