]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] backend: initialize the server stream_interface upon connect()
authorWilly Tarreau <w@1wt.eu>
Mon, 31 May 2010 15:44:19 +0000 (17:44 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 14 Jun 2010 08:53:15 +0000 (10:53 +0200)
It's not normal to initialize the server-side stream interface from the
accept() function, because it may change later. Thus, we introduce a new
stream_sock_prepare_interface() function which is called just before the
connect() and which sets all of the stream_interface's callbacks to the
default ones used for real sockets. The ->connect function is also set
at the same instant so that we can easily add new server-side protocols
soon.

include/proto/stream_sock.h
src/backend.c
src/stream_sock.c

index d0d172f190a1c3cc84a170fb010c099554285484..e5d4f517a994a1354633fa6570c3121619be10a5 100644 (file)
@@ -39,6 +39,7 @@ 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);
 
 
 /* This either returns the sockname or the original destination address. Code
index 0e99879627eb54bd18a42e4eff06222e779a4e3f..1fc6b2aaadda0e0ed8e3048eaaea04a2a2f9a5f7 100644 (file)
 #include <proto/lb_fwrr.h>
 #include <proto/lb_map.h>
 #include <proto/proto_http.h>
+#include <proto/proto_tcp.h>
 #include <proto/queue.h>
 #include <proto/server.h>
 #include <proto/session.h>
+#include <proto/stream_sock.h>
 #include <proto/task.h>
 
 /*
@@ -902,8 +904,11 @@ int connect_server(struct session *s)
                        return SN_ERR_INTERNAL;
        }
 
-       if (!s->req->cons->connect)
-               return SN_ERR_INTERNAL;
+       /* Prepare the stream interface for a TCP connection. Later
+        * we may assign a protocol-specific connect() function.
+        */
+       stream_sock_prepare_interface(s->req->cons);
+       s->req->cons->connect = tcpv4_connect_server;
 
        assign_tproxy_address(s);
 
index 171ed294cd86bdb6a89396b400a172e6fd4072c2..915979695251416a6310ce3b8f4751a283b2d92f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Functions operating on SOCK_STREAM and buffers.
  *
- * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
+ * Copyright 2000-2010 Willy Tarreau <w@1wt.eu>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -1221,6 +1221,17 @@ 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->update = stream_sock_data_finish;
+       si->shutr = stream_sock_shutr;
+       si->shutw = stream_sock_shutw;
+       si->chk_rcv = stream_sock_chk_rcv;
+       si->chk_snd = stream_sock_chk_snd;
+       si->iohandler = NULL;
+}
+
 
 /*
  * Local variables: