]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] replace client_retnclose() with stream_int_retnclose()
authorWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 18:48:07 +0000 (19:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 30 Nov 2008 18:48:07 +0000 (19:48 +0100)
This makes more sense to return a message to a stream interface
than to a session.

senddata.{c,h} have been removed.

Makefile
include/proto/proto_http.h
include/proto/senddata.h [deleted file]
include/proto/stream_interface.h
src/client.c
src/dumpstats.c
src/proto_http.c
src/proto_tcp.c
src/proto_uxst.c
src/senddata.c [deleted file]
src/stream_interface.c

index 1cdeac12566241d98033c5f027b7b80c7bad590d..1f940d3a47c93ae6f036dad29097d17c971e3782 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -452,7 +452,7 @@ OBJS = src/haproxy.o src/sessionhash.o src/base64.o src/protocols.o \
        src/time.o src/fd.o src/regex.o src/cfgparse.o src/server.o \
        src/checks.o src/queue.o src/client.o src/proxy.o src/proto_uxst.o \
        src/proto_http.o src/stream_sock.o src/appsession.o src/backend.o \
-       src/stream_interface.o src/senddata.o src/dumpstats.o src/proto_tcp.o \
+       src/stream_interface.o src/dumpstats.o src/proto_tcp.o \
        src/session.o src/hdr_idx.o src/ev_select.o \
        src/acl.o src/memory.o \
        src/ebtree.o src/eb32tree.o
index e291eae3d7e0be2fc77a55316e712d41d14ad71b..5b0df84f8938403b67acf1ec7715a296552de328 100644 (file)
@@ -65,7 +65,6 @@ int process_srv_conn(struct session *t);
 int process_request(struct session *t);
 int process_response(struct session *t);
 
-void client_retnclose(struct session *s, const struct chunk *msg);
 void srv_close_with_err(struct session *t, int err, int finst,
                        int status, const struct chunk *msg);
 
diff --git a/include/proto/senddata.h b/include/proto/senddata.h
deleted file mode 100644 (file)
index eb65803..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
-  include/proto/senddata.h
-  This file contains definitions of some primitives to send data to
-  clients over a socket and a buffer.
-
-  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
-  
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation, version 2.1
-  exclusively.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-#ifndef _PROTO_SENDDATA_H
-#define _PROTO_SENDDATA_H
-
-#include <common/config.h>
-#include <types/buffers.h>
-#include <types/session.h>
-
-void client_retnclose(struct session *s, const struct chunk *msg);
-
-#endif /* _PROTO_SENDDATA_H */
-
-/*
- * Local variables:
- *  c-indent-level: 8
- *  c-basic-offset: 8
- * End:
- */
index bbdcecc71612ead961b1c517dca873f463500bb2..9a67e813d31c493b8c0f50db7431b4ec44e9e00f 100644 (file)
@@ -32,6 +32,7 @@
 void stream_int_check_timeouts(struct stream_interface *si);
 void stream_int_report_error(struct stream_interface *si);
 void stream_int_return(struct stream_interface *si, const struct chunk *msg);
+void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg);
 
 #endif /* _PROTO_STREAM_INTERFACE_H */
 
index 8e8dc53f8944bb638e1fae25ba02ca7513fae3f0..bc7b2547eaf5f4fc3dcbeaa3c490962d5b5344de 100644 (file)
@@ -34,6 +34,7 @@
 #include <proto/hdr_idx.h>
 #include <proto/proto_http.h>
 #include <proto/session.h>
+#include <proto/stream_interface.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
 
@@ -411,13 +412,13 @@ int event_accept(int fd) {
                         * both cases, we return a fake "HTTP/1.0 200 OK" response and we exit.
                         */
                        struct chunk msg = { .str = "HTTP/1.0 200 OK\r\n\r\n", .len = 19 };
-                       client_retnclose(s, &msg); /* forge a 200 response */
+                       stream_int_retnclose(&s->si[0], &msg); /* forge a 200 response */
                        trace_term(s, TT_CLIENT_1);
                        t->expire = s->rep->wex;
                }
                else if (p->mode == PR_MODE_HEALTH) {  /* health check mode, no client reading */
                        struct chunk msg = { .str = "OK\n", .len = 3 };
-                       client_retnclose(s, &msg); /* forge an "OK" response */
+                       stream_int_retnclose(&s->si[0], &msg); /* forge an "OK" response */
                        trace_term(s, TT_CLIENT_2);
                        t->expire = s->rep->wex;
                }
index e4ef0b65599e2596267b5d49d1d59a14b3788684..c0abe9f27650091af59a4c6d448eddda8250f644 100644 (file)
@@ -42,9 +42,9 @@
 #include <proto/dumpstats.h>
 #include <proto/fd.h>
 #include <proto/proto_uxst.h>
-#include <proto/senddata.h>
 #include <proto/session.h>
 #include <proto/server.h>
+#include <proto/stream_interface.h>
 
 /* This function parses a "stats" statement in the "global" section. It returns
  * -1 if there is any error, otherwise zero. If it returns -1, it may write an
@@ -197,7 +197,7 @@ int stats_dump_raw(struct session *s, struct uri_auth *uri)
                /* the function had not been called yet, let's prepare the
                 * buffer for a response.
                 */
-               client_retnclose(s, &msg);
+               stream_int_retnclose(rep->cons, &msg);
                s->data_state = DATA_ST_HEAD;
                /* fall through */
 
@@ -326,7 +326,7 @@ int stats_dump_http(struct session *s, struct uri_auth *uri)
                chunk_printf(&msg, sizeof(trash), "\r\n");
 
                s->txn.status = 200;
-               client_retnclose(s, &msg); // send the start of the response.
+               stream_int_retnclose(rep->cons, &msg); // send the start of the response.
                msg.len = 0;
 
                if (!(s->flags & SN_ERR_MASK))  // this is not really an error but it is
index e3216415aaeb8327437c01b0793ba7c6e0d104fd..b8e4daa087af9be5e0a48f40e5020eb5509a7407 100644 (file)
@@ -48,7 +48,6 @@
 #include <proto/proto_tcp.h>
 #include <proto/proto_http.h>
 #include <proto/queue.h>
-#include <proto/senddata.h>
 #include <proto/session.h>
 #include <proto/stream_interface.h>
 #include <proto/stream_sock.h>
@@ -1762,7 +1761,7 @@ int process_request(struct session *t)
                        else if (req->flags & BF_READ_TIMEOUT || tick_is_expired(req->analyse_exp, now_ms)) {
                                /* read timeout : give up with an error message. */
                                txn->status = 408;
-                               client_retnclose(t, error_message(t, HTTP_ERR_408));
+                               stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_408));
                                msg->msg_state = HTTP_MSG_ERROR;
                                req->analysers = 0;
                                t->fe->failed_req++;
@@ -1776,7 +1775,7 @@ int process_request(struct session *t)
                        /* 4: have we encountered a close ? */
                        else if (req->flags & BF_SHUTR) {
                                txn->status = 400;
-                               client_retnclose(t, error_message(t, HTTP_ERR_400));
+                               stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_400));
                                msg->msg_state = HTTP_MSG_ERROR;
                                req->analysers = 0;
                                t->fe->failed_req++;
@@ -1848,14 +1847,14 @@ int process_request(struct session *t)
                                if (ret) {
                                        /* we fail this request, let's return 503 service unavail */
                                        txn->status = 503;
-                                       client_retnclose(t, error_message(t, HTTP_ERR_503));
+                                       stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_503));
                                        goto return_prx_cond;
                                }
                        }
 
                        /* nothing to fail, let's reply normaly */
                        txn->status = 200;
-                       client_retnclose(t, &http_200_chunk);
+                       stream_int_retnclose(req->prod, &http_200_chunk);
                        goto return_prx_cond;
                }
 
@@ -2026,7 +2025,7 @@ int process_request(struct session *t)
                                        txn->status = rule->code;
                                        /* let's log the request time */
                                        t->logs.tv_request = now;
-                                       client_retnclose(t, &rdr);
+                                       stream_int_retnclose(req->prod, &rdr);
                                        goto return_prx_cond;
                                }
                        }
@@ -2043,7 +2042,7 @@ int process_request(struct session *t)
                                        txn->status = 403;
                                        /* let's log the request time */
                                        t->logs.tv_request = now;
-                                       client_retnclose(t, error_message(t, HTTP_ERR_403));
+                                       stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_403));
                                        goto return_prx_cond;
                                }
                        }
@@ -2072,7 +2071,7 @@ int process_request(struct session *t)
                                txn->status = 403;
                                /* let's log the request time */
                                t->logs.tv_request = now;
-                               client_retnclose(t, error_message(t, HTTP_ERR_403));
+                               stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_403));
                                goto return_prx_cond;
                        }
 
@@ -2440,7 +2439,7 @@ int process_request(struct session *t)
                txn->req.msg_state = HTTP_MSG_ERROR;
                txn->status = 400;
                req->analysers = 0;
-               client_retnclose(t, error_message(t, HTTP_ERR_400));
+               stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_400));
                t->fe->failed_req++;
        return_prx_cond:
                if (!(t->flags & SN_ERR_MASK))
@@ -2475,7 +2474,7 @@ int process_request(struct session *t)
 
                txn->status = 500;
                if (req->flags != BF_READ_ERROR)
-                       client_retnclose(t, error_message(t, HTTP_ERR_500));
+                       stream_int_retnclose(req->prod, error_message(t, HTTP_ERR_500));
 
                req->analysers = 0;
                req->analyse_exp = TICK_ETERNITY;
@@ -3107,7 +3106,7 @@ int produce_content(struct session *s)
 
        /* unknown data source or internal error */
        s->txn.status = 500;
-       client_retnclose(s, error_message(s, HTTP_ERR_500));
+       stream_int_retnclose(s->rep->cons, error_message(s, HTTP_ERR_500));
        trace_term(s, TT_HTTP_CNT_1);
        if (!(s->flags & SN_ERR_MASK))
                s->flags |= SN_ERR_PRXCOND;
@@ -4475,7 +4474,7 @@ int stats_check_uri_auth(struct session *t, struct proxy *backend)
                msg.str = trash;
                msg.len = sprintf(trash, HTTP_401_fmt, uri_auth->auth_realm);
                txn->status = 401;
-               client_retnclose(t, &msg);
+               stream_int_retnclose(t->req->prod, &msg);
                trace_term(t, TT_HTTP_URI_1);
                t->req->analysers = 0;
                if (!(t->flags & SN_ERR_MASK))
index 32c4994cef82a33e9fc8b54328e933fc4f60fca7..adc32d1e0430ee844fbc404a05c2143411d121fc 100644 (file)
@@ -45,7 +45,6 @@
 #include <proto/proto_tcp.h>
 #include <proto/proxy.h>
 #include <proto/queue.h>
-#include <proto/senddata.h>
 #include <proto/session.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
index ee684a60d4e77bbb58f25446cff849d4d29d0770..4b0cd9e92c4f3403e7413d83e6a9302e496ad7d3 100644 (file)
@@ -47,7 +47,6 @@
 #include <proto/protocols.h>
 #include <proto/proto_uxst.h>
 #include <proto/queue.h>
-#include <proto/senddata.h>
 #include <proto/session.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
diff --git a/src/senddata.c b/src/senddata.c
deleted file mode 100644 (file)
index fd1d838..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Helper functions to send data over a socket and buffer.
- * Should probably move somewhere else, but where ?
- *
- * Copyright 2000-2008 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
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- *
- */
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <common/compat.h>
-#include <common/config.h>
-#include <common/debug.h>
-#include <common/memory.h>
-#include <common/standard.h>
-#include <common/ticks.h>
-#include <common/time.h>
-#include <common/version.h>
-
-#include <proto/backend.h>
-#include <proto/buffers.h>
-#include <proto/fd.h>
-#include <proto/senddata.h>
-#include <proto/session.h>
-
-/*
- * returns a message to the client ; the connection is shut down for read,
- * and the request is cleared so that no server connection can be initiated.
- * The client must be in a valid state for this (HEADER, DATA ...).
- * Nothing is performed on the server side. The message is contained in a
- * "chunk". If it is null, then an empty message is used.
- * The reply buffer doesn't need to be empty before this.
- */
-void client_retnclose(struct session *s, const struct chunk *msg)
-{
-       //FIXME: must move to lower level
-       //EV_FD_CLR(s->cli_fd, DIR_RD);
-       //EV_FD_SET(s->cli_fd, DIR_WR);
-       buffer_abort(s->req);
-
-       s->cli_state = CL_STSHUTR; // FIXME: still used by unix sockets
-       buffer_flush(s->rep);
-       buffer_shutr_now(s->rep);
-       if (msg && msg->len)
-               buffer_write(s->rep, msg->str, msg->len);
-
-       s->rep->wex = tick_add_ifset(now_ms, s->rep->wto);
-       buffer_write_ena(s->rep);
-}
-
-/*
- * Local variables:
- *  c-indent-level: 8
- *  c-basic-offset: 8
- * End:
- */
index 96087906f90d999e50cf938b68a6ad26d1a57d0e..c7f9b43e376979cdf7be2b8fccba963faacc2ee3 100644 (file)
@@ -71,6 +71,27 @@ void stream_int_return(struct stream_interface *si, const struct chunk *msg)
                buffer_write(si->ob, msg->str, msg->len);
 }
 
+/*
+ * Returns a message to the client ; the connection is shut down for read,
+ * and the request is cleared so that no server connection can be initiated.
+ * The buffer is marked for read shutdown on the other side to protect the
+ * message, and the buffer write is enabled. The message is contained in a
+ * "chunk". If it is null, then an empty message is used. The reply buffer
+ * doesn't need to be empty before this. The goal of this function is to
+ * return error messages to a client.
+ */
+void stream_int_retnclose(struct stream_interface *si, const struct chunk *msg)
+{
+       buffer_abort(si->ib);
+       buffer_flush(si->ob);
+       buffer_shutr_now(si->ob);
+       if (msg && msg->len)
+               buffer_write(si->ob, msg->str, msg->len);
+
+       si->ob->wex = tick_add_ifset(now_ms, si->ob->wto);
+       buffer_write_ena(si->ob);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8