blob: e81a2de87ea44f539241d61d1ed92ba8483afc5f [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
2 * Helper functions to send data over a socket and buffer.
3 * Should probably move somewhere else, but where ?
4 *
5 * Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 */
13
14#include <ctype.h>
15#include <errno.h>
16#include <fcntl.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <time.h>
21
22#include <sys/socket.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25
26#include <common/compat.h>
27#include <common/config.h>
28#include <common/debug.h>
29#include <common/memory.h>
30#include <common/standard.h>
31#include <common/time.h>
32#include <common/version.h>
33
34#include <types/client.h>
35#include <types/global.h>
36#include <types/polling.h>
37#include <types/proxy.h>
38#include <types/server.h>
39
40#include <proto/backend.h>
41#include <proto/buffers.h>
42#include <proto/fd.h>
43#include <proto/senddata.h>
44#include <proto/session.h>
45
46/*
47 * returns a message to the client ; the connection is shut down for read,
48 * and the request is cleared so that no server connection can be initiated.
49 * The client must be in a valid state for this (HEADER, DATA ...).
50 * Nothing is performed on the server side. The message is contained in a
51 * "chunk". If it is null, then an empty message is used.
52 * The reply buffer doesn't need to be empty before this.
53 */
54void client_retnclose(struct session *s, const struct chunk *msg)
55{
56 EV_FD_CLR(s->cli_fd, DIR_RD);
57 EV_FD_SET(s->cli_fd, DIR_WR);
58 buffer_shutr(s->req);
59 if (!tv_add_ifset(&s->rep->wex, &now, &s->rep->wto))
60 tv_eternity(&s->rep->wex);
61 s->cli_state = CL_STSHUTR;
62 buffer_flush(s->rep);
63 if (msg && msg->len)
64 buffer_write(s->rep, msg->str, msg->len);
65 s->req->l = 0;
66}
67
68
69/*
70 * returns a message into the rep buffer, and flushes the req buffer.
71 * The reply buffer doesn't need to be empty before this. The message
72 * is contained in a "chunk". If it is null, then an empty message is
73 * used.
74 */
75void client_return(struct session *s, const struct chunk *msg)
76{
77 buffer_flush(s->rep);
78 if (msg && msg->len)
79 buffer_write(s->rep, msg->str, msg->len);
80 s->req->l = 0;
81}
82
83/*
84 * Local variables:
85 * c-indent-level: 8
86 * c-basic-offset: 8
87 * End:
88 */