]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] process_srv: don't rely at all on client state
authorWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 18:38:13 +0000 (20:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 3 Aug 2008 20:47:10 +0000 (22:47 +0200)
A new buffer flag BF_MAY_CONNECT has been added so that the server
FSM can check whether it is allowed to establish a connection or
not. That way, the client FSM only has to move this flag and the
server side does not need to monitor client state anymore.

include/types/buffers.h
src/client.c
src/proto_http.c

index 7539901276f8132791d55e59a95108242a1a0969..8cc8d29a4ab3b54e4753e97f398c1735add2d6d3 100644 (file)
 
 #define BF_PARTIAL_WRITE      256
 #define BF_COMPLETE_WRITE     512
-#define BF_WRITE_ERROR        1024
-#define BF_WRITE_NULL         2048
-#define BF_WRITE_STATUS       (BF_PARTIAL_WRITE|BF_COMPLETE_WRITE|BF_WRITE_ERROR|BF_WRITE_NULL)
-#define BF_CLEAR_WRITE        (~BF_WRITE_STATUS)
+#define BF_WRITE_ERROR       1024
+#define BF_WRITE_NULL        2048
+#define BF_WRITE_STATUS      (BF_PARTIAL_WRITE|BF_COMPLETE_WRITE|BF_WRITE_ERROR|BF_WRITE_NULL)
+#define BF_CLEAR_WRITE       (~BF_WRITE_STATUS)
 
-#define BF_STREAMER           4096
-#define BF_STREAMER_FAST      8192
+#define BF_STREAMER          4096
+#define BF_STREAMER_FAST     8192
 
+#define BF_MAY_CONNECT      16384  /* consumer side is allowed to forward the connection */
 
 /* describes a chunk of string */
 struct chunk {
index a4d52652b45dbc759836df71bc1e72db06fa4bf2..e04a066ff2f2600f91a473fcf09ef91f584f3a09 100644 (file)
@@ -341,6 +341,9 @@ int event_accept(int fd) {
                if (p->mode == PR_MODE_HTTP) /* reserve some space for header rewriting */
                        s->req->rlim -= MAXREWRITE;
 
+               if (s->cli_state == CL_STDATA)
+                       s->req->flags |= BF_MAY_CONNECT;  /* don't wait to establish connection */
+
                s->req->rto = s->fe->timeout.client;
                s->req->wto = s->be->timeout.server;
                s->req->cto = s->be->timeout.connect;
index 42f253189fb575fd3caa083fc914f343bdd4c297..5d45f02042f3ab093d154f0a6f6683ca76b5d8d1 100644 (file)
@@ -1644,6 +1644,7 @@ int process_cli(struct session *t)
                        t->txn.exp = tick_add_ifset(now_ms, t->fe->timeout.httpreq);
                } else {
                        t->cli_state = CL_STDATA;
+                       req->flags |= BF_MAY_CONNECT;
                }
                t->inspect_exp = TICK_ETERNITY;
                return 1;
@@ -2365,6 +2366,8 @@ int process_cli(struct session *t)
                 ************************************************************/
 
                t->cli_state = CL_STDATA;
+               req->flags |= BF_MAY_CONNECT;
+
                req->rlim = req->data + BUFSIZE; /* no more rewrite needed */
 
                t->logs.tv_request = now;
@@ -2685,7 +2688,6 @@ int process_cli(struct session *t)
 int process_srv(struct session *t)
 {
        int s = t->srv_state;
-       int c = t->cli_state;
        struct http_txn *txn = &t->txn;
        struct buffer *req = t->req;
        struct buffer *rep = t->rep;
@@ -2696,44 +2698,13 @@ int process_srv(struct session *t)
                EV_FD_ISSET(t->srv_fd, DIR_RD), EV_FD_ISSET(t->srv_fd, DIR_WR),
                rep->rex, req->wex);
 
-#if 0
-       fprintf(stderr,"%s:%d  fe->clito=%d.%d, fe->conto=%d.%d, fe->srvto=%d.%d\n",
-               __FUNCTION__, __LINE__,
-               t->fe->timeout.client.tv_sec, t->fe->timeout.client.tv_usec, 
-               t->fe->timeout.connect.tv_sec, t->fe->timeout.connect.tv_usec, 
-               t->fe->timeout.server.tv_sec, t->fe->timeout.server.tv_usec);
-       fprintf(stderr,"%s:%d  be->clito=%d.%d, be->conto=%d.%d, be->srvto=%d.%d\n",
-               __FUNCTION__, __LINE__,
-               t->be->timeout.client.tv_sec, t->be->timeout.client.tv_usec, 
-               t->be->timeout.connect.tv_sec, t->be->timeout.connect.tv_usec, 
-               t->be->timeout.server.tv_sec, t->be->timeout.server.tv_usec);
-
-       fprintf(stderr,"%s:%d  req->cto=%d.%d, req->rto=%d.%d, req->wto=%d.%d\n",
-               __FUNCTION__, __LINE__,
-               req->cto.tv_sec, req->cto.tv_usec, 
-               req->rto.tv_sec, req->rto.tv_usec, 
-               req->wto.tv_sec, req->wto.tv_usec);
-
-       fprintf(stderr,"%s:%d  rep->cto=%d.%d, rep->rto=%d.%d, rep->wto=%d.%d\n",
-               __FUNCTION__, __LINE__,
-               rep->cto.tv_sec, rep->cto.tv_usec, 
-               rep->rto.tv_sec, rep->rto.tv_usec, 
-               rep->wto.tv_sec, rep->wto.tv_usec);
-#endif
-
-       //fprintf(stderr,"process_srv: c=%d, s=%d, cr=%d, cw=%d, sr=%d, sw=%d\n", c, s,
-       //EV_FD_ISSET(t->cli_fd, DIR_RD), EV_FD_ISSET(t->cli_fd, DIR_WR),
-       //EV_FD_ISSET(t->srv_fd, DIR_RD), EV_FD_ISSET(t->srv_fd, DIR_WR)
-       //);
        if (s == SV_STIDLE) {
                /* NOTE: The client processor may switch to SV_STANALYZE, which switches back SV_STIDLE.
                 *       This is logcially after CL_STHEADERS completed, CL_STDATA has started, but
                 *       we need to defer server selection until more data arrives, if possible.
                  *       This is rare, and only if balancing on parameter hash with values in the entity of a POST
                  */
-               if (c == CL_STHEADERS || c == CL_STINSPECT)
-                       return 0;       /* stay in idle, waiting for data to reach the client side */
-               else if ((rep->flags & BF_SHUTW_STATUS) ||
+               if ((rep->flags & BF_SHUTW_STATUS) ||
                         ((req->flags & BF_SHUTR_STATUS) &&
                          (req->l == 0 || t->be->options & PR_O_ABRT_CLOSE))) { /* give up */
                        req->cex = TICK_ETERNITY;
@@ -2749,7 +2720,8 @@ int process_srv(struct session *t)
 
                        return 1;
                }
-               else {
+               else if (req->flags & BF_MAY_CONNECT) {
+                       /* the client allows the server to connect */
                        if (txn->flags & TX_CLTARPIT) {
                                /* This connection is being tarpitted. The CLIENT side has
                                 * already set the connect expiration date to the right