]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stream-interface: provide a generic si_conn_send_cb callback
authorWilly Tarreau <wtarreau@exceliance.fr>
Mon, 20 Aug 2012 13:09:53 +0000 (15:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Sep 2012 19:54:55 +0000 (21:54 +0200)
The connection send() callback is supposed to be generic for a
stream-interface, and consists in calling the lower layer snd_buf
function. Move this function to the stream interface and remove
the sock-raw and sock-ssl clones.

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

index 844d9258a8d78130780f7af1b78f52270eec1166..8a4cf3a2aeea6f0012b2785838e8969d96d11302 100644 (file)
@@ -41,6 +41,7 @@ int stream_int_shutr(struct stream_interface *si);
 int stream_int_shutw(struct stream_interface *si);
 void stream_int_chk_rcv_conn(struct stream_interface *si);
 void stream_int_chk_snd_conn(struct stream_interface *si);
+void si_conn_send_cb(struct connection *conn);
 
 extern struct sock_ops stream_int_embedded;
 extern struct sock_ops stream_int_task;
index e21177cd17b412e648cccef6eca46b48377a99a6..5b20f2ff59baf9c5ca141a522e06f2daf528836b 100644 (file)
@@ -44,7 +44,6 @@
 
 /* main event functions used to move data between sockets and buffers */
 static void sock_raw_read(struct connection *conn);
-static void sock_raw_write(struct connection *conn);
 static void sock_raw_read0(struct stream_interface *si);
 
 
@@ -592,38 +591,6 @@ static int sock_raw_write_loop(struct connection *conn)
 }
 
 
-/*
- * This function is called on a write event from a stream socket.
- */
-static void sock_raw_write(struct connection *conn)
-{
-       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
-       struct buffer *b = si->ob;
-
-#ifdef DEBUG_FULL
-       fprintf(stderr,"sock_raw_write : fd=%d, owner=%p\n", fd, fdtab[fd].owner);
-#endif
-
-       if (conn->flags & CO_FL_ERROR)
-               goto out_error;
-
-       /* we might have been called just after an asynchronous shutw */
-       if (b->flags & BF_SHUTW)
-               return;
-
-       if (conn_data_snd_buf(conn) < 0)
-               goto out_error;
-
-       /* OK all done */
-       return;
-
- out_error:
-       /* Write error on the connection, report the error and stop I/O */
-
-       conn->flags |= CO_FL_ERROR;
-       conn_data_stop_both(conn);
-}
-
 /*
  * This function propagates a null read received on a connection. It updates
  * the stream interface. If the stream interface has SI_FL_NOHALF, we also
@@ -681,7 +648,7 @@ struct sock_ops sock_raw = {
        .chk_rcv = stream_int_chk_rcv_conn,
        .chk_snd = stream_int_chk_snd_conn,
        .read    = sock_raw_read,
-       .write   = sock_raw_write,
+       .write   = si_conn_send_cb,
        .snd_buf = sock_raw_write_loop,
        .close   = NULL,
 };
index 06a5d4e682b065ace8efcb1f490687d826360718..6be0354e8dca4c6f6ebf8233c096b189ba7111c5 100644 (file)
@@ -864,6 +864,40 @@ void stream_int_chk_snd_conn(struct stream_interface *si)
        }
 }
 
+/*
+ * This is the callback which is called by the connection layer to send data
+ * from the buffer to the connection. It iterates over the data layer's snd_buf
+ * function.
+ */
+void si_conn_send_cb(struct connection *conn)
+{
+       struct stream_interface *si = container_of(conn, struct stream_interface, conn);
+       struct buffer *b = si->ob;
+
+       if (conn->flags & CO_FL_ERROR)
+               goto out_error;
+
+       if (si->conn.flags & CO_FL_HANDSHAKE)
+               /* a handshake was requested */
+               return;
+
+       /* we might have been called just after an asynchronous shutw */
+       if (b->flags & BF_SHUTW)
+               return;
+
+       /* OK there are data waiting to be sent */
+       if (conn_data_snd_buf(conn) < 0)
+               goto out_error;
+
+       /* OK all done */
+       return;
+
+ out_error:
+       /* Write error on the connection, report the error and stop I/O */
+       conn->flags |= CO_FL_ERROR;
+       conn_data_stop_both(conn);
+}
+
 
 /*
  * Local variables: