]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: connection: move conn_drain() to connection.c and rename it
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2015 23:40:28 +0000 (00:40 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2015 23:42:48 +0000 (00:42 +0100)
It's now called conn_sock_drain() to make it clear that it only reads
at the sock layer and not at the data layer. The function was too big
to remain inlined and it's used at a few places where size counts.

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

index f542cb2dbea8ecc635f483348150635f1d2f7748..2fb25cc29fbef6a311ebb2ea60e6ec2b7c02b005 100644 (file)
@@ -48,6 +48,9 @@ int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connec
 /* raw send() directly on the socket */
 int conn_sock_send(struct connection *conn, const void *buf, int len, int flags);
 
+/* drains any pending bytes from the socket */
+int conn_sock_drain(struct connection *conn);
+
 /* returns true is the transport layer is ready */
 static inline int conn_xprt_ready(const struct connection *conn)
 {
@@ -540,42 +543,6 @@ 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)
-{
-       if (!conn_ctrl_ready(conn))
-               return 1;
-
-       if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))
-               return 1;
-
-       if (fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
-               fdtab[conn->t.sock.fd].linger_risk = 0;
-       }
-       else {
-               if (!fd_recv_ready(conn->t.sock.fd))
-                       return 0;
-
-               /* disable draining if we were called and have no drain function */
-               if (!conn->ctrl->drain) {
-                       __conn_data_stop_recv(conn);
-                       return 0;
-               }
-
-               if (conn->ctrl->drain(conn->t.sock.fd) <= 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.
  */
index f61bc9c7866c5dbf6b627fea97d24c23e4123aab..2ef14d10291b00ce4464b96ebbe8d317f3c32508 100644 (file)
@@ -1340,7 +1340,7 @@ static int wake_srv_chk(struct connection *conn)
                /* We're here because nobody wants to handle the error, so we
                 * sure want to abort the hard way.
                 */
-               conn_drain(conn);
+               conn_sock_drain(conn);
                conn_force_close(conn);
        }
        return 0;
@@ -2079,7 +2079,7 @@ static struct task *process_chk_conn(struct task *t)
                         * as a failed response coupled with "observe layer7" caused the
                         * server state to be suddenly changed.
                         */
-                       conn_drain(conn);
+                       conn_sock_drain(conn);
                        conn_force_close(conn);
                }
 
index 8b3c835e767de5843f4ba6e0a29de7715d184308..efcd6e123d58db092db1ac938f8a6d1e93448d7f 100644 (file)
@@ -268,6 +268,42 @@ int conn_sock_send(struct connection *conn, const void *buf, int len, int flags)
        return ret;
 }
 
+/* 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.
+ */
+int conn_sock_drain(struct connection *conn)
+{
+       if (!conn_ctrl_ready(conn))
+               return 1;
+
+       if (conn->flags & (CO_FL_ERROR | CO_FL_SOCK_RD_SH))
+               return 1;
+
+       if (fdtab[conn->t.sock.fd].ev & (FD_POLL_ERR|FD_POLL_HUP)) {
+               fdtab[conn->t.sock.fd].linger_risk = 0;
+       }
+       else {
+               if (!fd_recv_ready(conn->t.sock.fd))
+                       return 0;
+
+               /* disable draining if we were called and have no drain function */
+               if (!conn->ctrl->drain) {
+                       __conn_data_stop_recv(conn);
+                       return 0;
+               }
+
+               if (conn->ctrl->drain(conn->t.sock.fd) <= 0)
+                       return 0;
+       }
+
+       conn->flags |= CO_FL_SOCK_RD_SH;
+       return 1;
+}
+
 /*
  * Get data length from tlv
  */
index bc209089079e54914106d338a7dcd3f9b9e6c45c..77c44904de04995fec29f9f22827095d23c739da 100644 (file)
@@ -2466,7 +2466,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                                 * TCP sockets. We first try to drain possibly pending
                                 * data to avoid this as much as possible.
                                 */
-                               conn_drain(conn);
+                               conn_sock_drain(conn);
                                if (!conn->err_code)
                                        conn->err_code = (conn->xprt_st & SSL_SOCK_RECV_HEARTBEAT) ?
                                                CO_ER_SSL_KILLED_HB : CO_ER_SSL_HANDSHAKE;
@@ -2532,7 +2532,7 @@ int ssl_sock_handshake(struct connection *conn, unsigned int flag)
                         * TCP sockets. We first try to drain possibly pending
                         * data to avoid this as much as possible.
                         */
-                       conn_drain(conn);
+                       conn_sock_drain(conn);
                        if (!conn->err_code)
                                conn->err_code = (conn->xprt_st & SSL_SOCK_RECV_HEARTBEAT) ?
                                        CO_ER_SSL_KILLED_HB : CO_ER_SSL_HANDSHAKE;
index 8450117c236ca3483fa4c994d541fd7d912f21dd..1d8cec2fcb6d367c0c7dd581568deff6548c803d 100644 (file)
@@ -497,7 +497,7 @@ int conn_si_send_proxy(struct connection *conn, unsigned int flag)
  */
 static void si_idle_conn_null_cb(struct connection *conn)
 {
-       conn_drain(conn);
+       conn_sock_drain(conn);
 }
 
 /* Callback to be used by connection I/O handlers when some activity is detected