From eecf6ca68a6749d2f58bfa069dfd3887b24d8862 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 20 Aug 2012 15:09:53 +0200 Subject: [PATCH] MEDIUM: stream-interface: provide a generic si_conn_send_cb callback 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 | 1 + src/sock_raw.c | 35 +------------------------------- src/stream_interface.c | 34 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 34 deletions(-) diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 844d9258a..8a4cf3a2a 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -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; diff --git a/src/sock_raw.c b/src/sock_raw.c index e21177cd1..5b20f2ff5 100644 --- a/src/sock_raw.c +++ b/src/sock_raw.c @@ -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, }; diff --git a/src/stream_interface.c b/src/stream_interface.c index 06a5d4e68..6be0354e8 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -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: