From: Willy Tarreau Date: Mon, 7 May 2012 15:01:39 +0000 (+0200) Subject: REORG/MEDIUM: move protocol->{read,write} to sock_ops X-Git-Tag: v1.5-dev9~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b79bdee2692888ddfcb818f21f0932ebe131a0d;p=thirdparty%2Fhaproxy.git REORG/MEDIUM: move protocol->{read,write} to sock_ops The protocol must not set the read and write callbacks, they're specific to the socket layer. Move them to sock_ops instead. --- diff --git a/include/types/protocols.h b/include/types/protocols.h index eba4874b52..104cee56ff 100644 --- a/include/types/protocols.h +++ b/include/types/protocols.h @@ -149,8 +149,6 @@ struct protocol { socklen_t sock_addrlen; /* socket address length, used by bind() */ int l3_addrlen; /* layer3 address length, used by hashes */ int (*accept)(int fd); /* generic accept function */ - int (*read)(int fd); /* generic read function */ - int (*write)(int fd); /* generic write function */ int (*bind)(struct listener *l, char *errmsg, int errlen); /* bind a listener */ int (*bind_all)(struct protocol *proto, char *errmsg, int errlen); /* bind all unbound listeners */ int (*unbind_all)(struct protocol *proto); /* unbind all bound listeners */ diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 1f0d6dce77..f709e73655 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -70,8 +70,6 @@ static struct protocol proto_tcpv4 = { .sock_addrlen = sizeof(struct sockaddr_in), .l3_addrlen = 32/8, .accept = &stream_sock_accept, - .read = &stream_sock_read, - .write = &stream_sock_write, .bind = tcp_bind_listener, .bind_all = tcp_bind_listeners, .unbind_all = unbind_all_listeners, @@ -90,8 +88,6 @@ static struct protocol proto_tcpv6 = { .sock_addrlen = sizeof(struct sockaddr_in6), .l3_addrlen = 128/8, .accept = &stream_sock_accept, - .read = &stream_sock_read, - .write = &stream_sock_write, .bind = tcp_bind_listener, .bind_all = tcp_bind_listeners, .unbind_all = unbind_all_listeners, @@ -446,9 +442,9 @@ int tcp_connect_server(struct stream_interface *si) fdtab[fd].owner = si; fdtab[fd].state = FD_STCONN; /* connection in progress */ fdtab[fd].flags = FD_FL_TCP | FD_FL_TCP_NODELAY; - fdtab[fd].cb[DIR_RD].f = &stream_sock_read; + fdtab[fd].cb[DIR_RD].f = si->sock.read; fdtab[fd].cb[DIR_RD].b = si->ib; - fdtab[fd].cb[DIR_WR].f = &stream_sock_write; + fdtab[fd].cb[DIR_WR].f = si->sock.write; fdtab[fd].cb[DIR_WR].b = si->ob; fdinfo[fd].peeraddr = (struct sockaddr *)&si->addr.to; diff --git a/src/proto_uxst.c b/src/proto_uxst.c index 6fb7264d52..2140ae6cae 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -56,8 +56,6 @@ static struct protocol proto_unix = { .sock_addrlen = sizeof(struct sockaddr_un), .l3_addrlen = sizeof(((struct sockaddr_un*)0)->sun_path),/* path len */ .accept = &stream_sock_accept, - .read = &stream_sock_read, - .write = &stream_sock_write, .bind = uxst_bind_listener, .bind_all = uxst_bind_listeners, .unbind_all = uxst_unbind_listeners, diff --git a/src/session.c b/src/session.c index fabba1f201..96b93b9624 100644 --- a/src/session.c +++ b/src/session.c @@ -285,9 +285,9 @@ int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) fdtab[cfd].owner = &s->si[0]; fdtab[cfd].state = FD_STREADY; fdtab[cfd].flags = 0; - fdtab[cfd].cb[DIR_RD].f = l->proto->read; + fdtab[cfd].cb[DIR_RD].f = s->si[0].sock.read; fdtab[cfd].cb[DIR_RD].b = s->req; - fdtab[cfd].cb[DIR_WR].f = l->proto->write; + fdtab[cfd].cb[DIR_WR].f = s->si[0].sock.write; fdtab[cfd].cb[DIR_WR].b = s->rep; fdinfo[cfd].peeraddr = (struct sockaddr *)&s->si[0].addr.from; fdinfo[cfd].peerlen = sizeof(s->si[0].addr.from); diff --git a/src/stream_interface.c b/src/stream_interface.c index 209762382e..b6188d0b79 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -313,6 +313,8 @@ struct task *stream_int_register_handler(struct stream_interface *si, struct si_ 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; si->connect = NULL; set_target_applet(&si->target, app); si->applet.state = 0; @@ -340,6 +342,8 @@ struct task *stream_int_register_handler_task(struct stream_interface *si, 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; si->connect = NULL; clear_target(&si->target); si->release = NULL; diff --git a/src/stream_sock.c b/src/stream_sock.c index 3862ac8630..a77ad39286 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -1305,6 +1305,8 @@ void stream_sock_prepare_interface(struct stream_interface *si) 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; }