From 46a8d925c2f1317ecebfefff52a646f145aa1285 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 20 Aug 2012 12:38:36 +0200 Subject: [PATCH] MEDIUM: stream-interface: offer a generic chk_rcv function for connections sock_raw and sock_ssl use a pretty generic chk_rcv function, so let's move this function to the stream_interface and remove specific functions. Later we might have a single chk_rcv function. --- include/proto/stream_interface.h | 1 + src/sock_raw.c | 37 +------------------------------- src/stream_interface.c | 32 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index 5e2d74f6b..24072a612 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -39,6 +39,7 @@ void conn_notify_si(struct connection *conn); void stream_int_update_conn(struct stream_interface *si); 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); 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 6a3a2565c..c426e995b 100644 --- a/src/sock_raw.c +++ b/src/sock_raw.c @@ -46,7 +46,6 @@ 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); -static void sock_raw_chk_rcv(struct stream_interface *si); static void sock_raw_chk_snd(struct stream_interface *si); @@ -673,40 +672,6 @@ static void sock_raw_read0(struct stream_interface *si) return; } -/* This function is used for inter-stream-interface calls. It is called by the - * consumer to inform the producer side that it may be interested in checking - * for free space in the buffer. Note that it intentionally does not update - * timeouts, so that we can still check them later at wake-up. - */ -static void sock_raw_chk_rcv(struct stream_interface *si) -{ - struct buffer *ib = si->ib; - - DPRINTF(stderr,"[%u] %s: fd=%d owner=%p ib=%p, ob=%p, exp(r,w)=%u,%u ibf=%08x obf=%08x ibh=%d ibt=%d obh=%d obd=%d si=%d\n", - now_ms, __FUNCTION__, - si_fd(si), fdtab[si_fd(si)].owner, - ib, si->ob, - ib->rex, si->ob->wex, - ib->flags, si->ob->flags, - ib->i, ib->o, si->ob->i, si->ob->o, si->state); - - if (unlikely(si->state != SI_ST_EST || (ib->flags & BF_SHUTR))) - return; - - if (ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) { - /* stop reading */ - if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL) - si->flags |= SI_FL_WAIT_ROOM; - conn_data_stop_recv(&si->conn); - } - else { - /* (re)start reading */ - si->flags &= ~SI_FL_WAIT_ROOM; - conn_data_want_recv(&si->conn); - } -} - - /* This function is used for inter-stream-interface calls. It is called by the * producer to inform the consumer side that it may be interested in checking * for data in the buffer. Note that it intentionally does not update timeouts, @@ -811,7 +776,7 @@ struct sock_ops sock_raw = { .update = stream_int_update_conn, .shutr = NULL, .shutw = NULL, - .chk_rcv = sock_raw_chk_rcv, + .chk_rcv = stream_int_chk_rcv_conn, .chk_snd = sock_raw_chk_snd, .read = sock_raw_read, .write = sock_raw_write, diff --git a/src/stream_interface.c b/src/stream_interface.c index e3816e414..6a46df40a 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -734,6 +734,38 @@ void stream_int_update_conn(struct stream_interface *si) } } +/* This function is used for inter-stream-interface calls. It is called by the + * consumer to inform the producer side that it may be interested in checking + * for free space in the buffer. Note that it intentionally does not update + * timeouts, so that we can still check them later at wake-up. This function is + * dedicated to connection-based stream interfaces. + */ +void stream_int_chk_rcv_conn(struct stream_interface *si) +{ + struct buffer *ib = si->ib; + + if (unlikely(si->state != SI_ST_EST || (ib->flags & BF_SHUTR))) + return; + + if (si->conn.flags & CO_FL_HANDSHAKE) { + /* a handshake is in progress */ + return; + } + + if (ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) { + /* stop reading */ + if ((ib->flags & (BF_FULL|BF_HIJACK|BF_DONT_READ)) == BF_FULL) + si->flags |= SI_FL_WAIT_ROOM; + conn_data_stop_recv(&si->conn); + } + else { + /* (re)start reading */ + si->flags &= ~SI_FL_WAIT_ROOM; + conn_data_want_recv(&si->conn); + } +} + + /* * Local variables: * c-indent-level: 8