]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream-interface: add a snd_buf() callback to sock_ops
authorWilly Tarreau <wtarreau@exceliance.fr>
Mon, 20 Aug 2012 12:02:10 +0000 (14:02 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:54:18 +0000 (21:54 +0200)
This callback is used to send data from the buffer to the socket. It is
the old write_loop() call of the data layer which is used both by the
->write() callback and the ->chk_snd() function. The reason for having
it as a pointer is that it's the only remaining part which causes the
write and chk_snd() functions to be different between raw and ssl.

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

index 2ecdfd3c5afd3a3ba5ede53e785b1025211acfc7..07568aaefa1f6cd4117d2f5c140d2814b65e1847 100644 (file)
@@ -37,6 +37,16 @@ static inline void conn_data_close(struct connection *conn)
                conn->data->close(conn);
 }
 
+/* Calls the snd_buf() function of the data layer if any, otherwise
+ * returns 0.
+ */
+static inline int conn_data_snd_buf(struct connection *conn)
+{
+       if (!conn->data->snd_buf)
+               return 0;
+       return conn->data->snd_buf(conn);
+}
+
 /* set polling depending on the change between the CURR part of the
  * flags and the new flags in connection C. The connection flags are
  * updated with the new flags at the end of the operation. Only the bits
index 6fbf94d04f059f1547e60c2c3838bc1fed059620..e181d570c4087d24eb91c3dc12521557edd25136 100644 (file)
@@ -117,7 +117,7 @@ struct sock_ops {
        void (*read)(struct connection *conn);      /* read callback after poll() */
        void (*write)(struct connection *conn);     /* write callback after poll() */
        void (*close)(struct connection *);         /* close the data channel on the connection */
-
+       int  (*snd_buf)(struct connection *conn);   /* callback used to send a buffer contents */
 };
 
 /* A stream interface has 3 parts :
index c426e995b5ac5cbb266f782c2977eabfd21ea536..f5aadcd18bed089e51716df469b0b74aec1b0067 100644 (file)
@@ -452,8 +452,10 @@ static void sock_raw_read(struct connection *conn)
  * This function is called to send buffer data to a stream socket.
  * It returns -1 in case of unrecoverable error, otherwise zero.
  */
-static int sock_raw_write_loop(struct stream_interface *si, struct buffer *b)
+static int sock_raw_write_loop(struct connection *conn)
 {
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
+       struct buffer *b = si->ob;
        int write_poll = MAX_WRITE_POLL_LOOPS;
        int ret, max;
 
@@ -610,7 +612,7 @@ static void sock_raw_write(struct connection *conn)
        if (b->flags & BF_SHUTW)
                return;
 
-       if (sock_raw_write_loop(si, b) < 0)
+       if (conn_data_snd_buf(conn) < 0)
                goto out_error;
 
        /* OK all done */
@@ -700,7 +702,7 @@ static void sock_raw_chk_snd(struct stream_interface *si)
             (fdtab[si_fd(si)].ev & FD_POLL_OUT)))   /* we'll be called anyway */
                return;
 
-       if (sock_raw_write_loop(si, ob) < 0) {
+       if (conn_data_snd_buf(&si->conn) < 0) {
                /* Write error on the file descriptor. We mark the FD as STERROR so
                 * that we don't use it anymore and we notify the task.
                 */
@@ -780,6 +782,7 @@ struct sock_ops sock_raw = {
        .chk_snd = sock_raw_chk_snd,
        .read    = sock_raw_read,
        .write   = sock_raw_write,
+       .snd_buf = sock_raw_write_loop,
        .close   = NULL,
 };