From dded32defa35d73212f1d2adea30780e0bae9059 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 30 Nov 2008 19:48:07 +0100 Subject: [PATCH] [MINOR] replace client_retnclose() with stream_int_retnclose() This makes more sense to return a message to a stream interface than to a session. senddata.{c,h} have been removed. --- Makefile | 2 +- include/proto/proto_http.h | 1 - include/proto/senddata.h | 39 ------------------ include/proto/stream_interface.h | 1 + src/client.c | 5 ++- src/dumpstats.c | 6 +-- src/proto_http.c | 23 +++++------ src/proto_tcp.c | 1 - src/proto_uxst.c | 1 - src/senddata.c | 71 -------------------------------- src/stream_interface.c | 21 ++++++++++ 11 files changed, 40 insertions(+), 131 deletions(-) delete mode 100644 include/proto/senddata.h delete mode 100644 src/senddata.c diff --git a/Makefile b/Makefile index 1cdeac1256..1f940d3a47 100644 --- 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 diff --git a/include/proto/proto_http.h b/include/proto/proto_http.h index e291eae3d7..5b0df84f89 100644 --- a/include/proto/proto_http.h +++ b/include/proto/proto_http.h @@ -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 index eb65803713..0000000000 --- a/include/proto/senddata.h +++ /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 -#include -#include - -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: - */ diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index bbdcecc716..9a67e813d3 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -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 */ diff --git a/src/client.c b/src/client.c index 8e8dc53f89..bc7b2547ea 100644 --- a/src/client.c +++ b/src/client.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -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; } diff --git a/src/dumpstats.c b/src/dumpstats.c index e4ef0b6559..c0abe9f276 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -42,9 +42,9 @@ #include #include #include -#include #include #include +#include /* 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 diff --git a/src/proto_http.c b/src/proto_http.c index e3216415aa..b8e4daa087 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -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)) diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 32c4994cef..adc32d1e04 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/src/proto_uxst.c b/src/proto_uxst.c index ee684a60d4..4b0cd9e92c 100644 --- a/src/proto_uxst.c +++ b/src/proto_uxst.c @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include diff --git a/src/senddata.c b/src/senddata.c deleted file mode 100644 index fd1d8389bf..0000000000 --- a/src/senddata.c +++ /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 - * - * 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -/* - * 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: - */ diff --git a/src/stream_interface.c b/src/stream_interface.c index 96087906f9..c7f9b43e37 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -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 -- 2.47.3