]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG/MEDIUM: stream_interface: initialize socket ops from descriptors
authorWilly Tarreau <w@1wt.eu>
Mon, 7 May 2012 15:15:39 +0000 (17:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 19:28:14 +0000 (21:28 +0200)
include/proto/stream_interface.h
include/proto/stream_sock.h
src/backend.c
src/peers.c
src/session.c
src/stream_interface.c
src/stream_sock.c

index ec8d5d081d405f25bac7afced5ca305b72c31c14..21236962072cbe665a93afbad3bb65cac2516d3a 100644 (file)
@@ -41,6 +41,9 @@ void stream_int_shutw(struct stream_interface *si);
 void stream_int_chk_rcv(struct stream_interface *si);
 void stream_int_chk_snd(struct stream_interface *si);
 
+extern struct sock_ops stream_int_embedded;
+extern struct sock_ops stream_int_task;
+
 struct task *stream_int_register_handler(struct stream_interface *si,
                                         struct si_applet *app);
 struct task *stream_int_register_handler_task(struct stream_interface *si,
@@ -95,6 +98,11 @@ static inline struct server *target_srv(struct target *t)
        return t->ptr.s;
 }
 
+static inline void stream_interface_prepare(struct stream_interface *si, const struct sock_ops *ops)
+{
+       memcpy(&si->sock, ops, sizeof(si->sock));
+}
+
 #endif /* _PROTO_STREAM_INTERFACE_H */
 
 /*
index 9e1bc3f1ab5e9651c0189e4d4ed8f212399ac0b6..f66d32192a7b63a7c9d6b6655c8cc6dc1c162013 100644 (file)
@@ -39,8 +39,8 @@ void stream_sock_shutr(struct stream_interface *si);
 void stream_sock_shutw(struct stream_interface *si);
 void stream_sock_chk_rcv(struct stream_interface *si);
 void stream_sock_chk_snd(struct stream_interface *si);
-void stream_sock_prepare_interface(struct stream_interface *si);
 
+extern struct sock_ops stream_sock;
 
 /* This either returns the sockname or the original destination address. Code
  * inspired from Patrick Schaaf's example of nf_getsockname() implementation.
index 5bec608ff38ab40ca8801349ffcde87ad12289e5..f125931818b678f1d9da6e99057d02cdb64a2af9 100644 (file)
@@ -973,7 +973,7 @@ int connect_server(struct session *s)
         * decide here if we can reuse the connection by comparing the
         * session's freshly assigned target with the stream interface's.
         */
-       stream_sock_prepare_interface(s->req->cons);
+       stream_interface_prepare(s->req->cons, &stream_sock);
        s->req->cons->connect = tcp_connect_server;
        s->req->cons->get_src = getsockname;
        s->req->cons->get_dst = getpeername;
index 8c8795af2721de3f23fb17fd9e1b8a0dd23a5d1c..31fb8d95376ea2f329b596d60573b610d2aeb1f4 100644 (file)
@@ -1182,7 +1182,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
        if (s->be->options2 & PR_O2_INDEPSTR)
                s->si[1].flags |= SI_FL_INDEP_STR;
 
-       stream_sock_prepare_interface(&s->si[1]);
+       stream_interface_prepare(&s->si[1], &stream_sock);
        s->si[1].release = NULL;
 
        session_init_srv_conn(s);
index 96b93b96241c2295a15b3b7022779fc70e322c65..5cddabdf85374aa2f2002b323e026f641892a4b2 100644 (file)
@@ -184,7 +184,7 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr)
                s->si[0].flags = SI_FL_CAP_SPLTCP; /* TCP/TCPv6 splicing possible */
 
        /* add the various callbacks */
-       stream_sock_prepare_interface(&s->si[0]);
+       stream_interface_prepare(&s->si[0], &stream_sock);
 
        /* pre-initialize the other side's stream interface to an INIT state. The
         * callbacks will be initialized before attempting to connect.
index b6188d0b790c6c1f2c1315c4f2ea23d5823f6f45..35ebc30596fefb4bbe0c9f1580dccdd34eed3d34 100644 (file)
 #include <proto/stream_sock.h>
 #include <proto/task.h>
 
+/* socket operations for embedded tasks */
+struct sock_ops stream_int_embedded = {
+       .update  = stream_int_update_embedded,
+       .shutr   = stream_int_shutr,
+       .shutw   = stream_int_shutw,
+       .chk_rcv = stream_int_chk_rcv,
+       .chk_snd = stream_int_chk_snd,
+       .read    = NULL,
+       .write   = NULL,
+};
+
+/* socket operations for external tasks */
+struct sock_ops stream_int_task = {
+       .update  = stream_int_update,
+       .shutr   = stream_int_shutr,
+       .shutw   = stream_int_shutw,
+       .chk_rcv = stream_int_chk_rcv,
+       .chk_snd = stream_int_chk_snd,
+       .read    = NULL,
+       .write   = NULL,
+};
+
 /*
  * This function only has to be called once after a wakeup event in case of
  * suspected timeout. It controls the stream interface timeouts and sets
@@ -308,13 +330,7 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_
 {
        DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si->owner);
 
-       si->sock.update  = stream_int_update_embedded;
-       si->sock.shutr   = stream_int_shutr;
-       si->sock.shutw   = stream_int_shutw;
-       si->sock.chk_rcv = stream_int_chk_rcv;
-       si->sock.chk_snd = stream_int_chk_snd;
-       si->sock.read    = NULL;
-       si->sock.write   = NULL;
+       stream_interface_prepare(si, &stream_int_embedded);
        si->connect = NULL;
        set_target_applet(&si->target, app);
        si->applet.state = 0;
@@ -337,13 +353,7 @@ struct task *stream_int_register_handler_task(struct stream_interface *si,
 
        DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", fct, si, si->owner);
 
-       si->sock.update  = stream_int_update;
-       si->sock.shutr   = stream_int_shutr;
-       si->sock.shutw   = stream_int_shutw;
-       si->sock.chk_rcv = stream_int_chk_rcv;
-       si->sock.chk_snd = stream_int_chk_snd;
-       si->sock.read    = NULL;
-       si->sock.write   = NULL;
+       stream_interface_prepare(si, &stream_int_task);
        si->connect = NULL;
        clear_target(&si->target);
        si->release   = NULL;
index a77ad392863221887cefa5cc006f4d51c0d2048d..93e0a9283f87182896b521820b81dcb6f80e4f3b 100644 (file)
@@ -1296,19 +1296,16 @@ int stream_sock_accept(int fd)
        return 0;
 }
 
-
-/* Prepare a stream interface to be used in socket mode. */
-void stream_sock_prepare_interface(struct stream_interface *si)
-{
-       si->sock.update  = stream_sock_data_finish;
-       si->sock.shutr   = stream_sock_shutr;
-       si->sock.shutw   = stream_sock_shutw;
-       si->sock.chk_rcv = stream_sock_chk_rcv;
-       si->sock.chk_snd = stream_sock_chk_snd;
-       si->sock.read    = stream_sock_read;
-       si->sock.write   = stream_sock_write;
-}
-
+/* stream sock operations */
+struct sock_ops stream_sock = {
+       .update  = stream_sock_data_finish,
+       .shutr   = stream_sock_shutr,
+       .shutw   = stream_sock_shutw,
+       .chk_rcv = stream_sock_chk_rcv,
+       .chk_snd = stream_sock_chk_snd,
+       .read    = stream_sock_read,
+       .write   = stream_sock_write,
+};
 
 /*
  * Local variables: