[MEDIUM] backend: initialize the server stream_interface upon connect()
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.
diff --git a/src/backend.c b/src/backend.c
index 0e99879..1fc6b2a 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -35,9 +35,11 @@
#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 @@
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);