blob: 5d6174ce03c8354b5945b6bb5cdd5364b710384f [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 *
Willy Tarreau0c303ee2008-07-07 00:09:58 +02005 * Copyright 2000-2008 Willy Tarreau <w@1wt.eu>
Willy Tarreau91861262007-10-17 17:06:05 +02006 *
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>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020031#include <common/ticks.h>
Willy Tarreau91861262007-10-17 17:06:05 +020032#include <common/time.h>
33#include <common/version.h>
34
Willy Tarreau91861262007-10-17 17:06:05 +020035#include <proto/backend.h>
36#include <proto/buffers.h>
37#include <proto/fd.h>
38#include <proto/senddata.h>
39#include <proto/session.h>
40
41/*
42 * returns a message to the client ; the connection is shut down for read,
43 * and the request is cleared so that no server connection can be initiated.
44 * The client must be in a valid state for this (HEADER, DATA ...).
45 * Nothing is performed on the server side. The message is contained in a
46 * "chunk". If it is null, then an empty message is used.
47 * The reply buffer doesn't need to be empty before this.
48 */
49void client_retnclose(struct session *s, const struct chunk *msg)
50{
51 EV_FD_CLR(s->cli_fd, DIR_RD);
52 EV_FD_SET(s->cli_fd, DIR_WR);
53 buffer_shutr(s->req);
Willy Tarreau0c303ee2008-07-07 00:09:58 +020054 s->rep->wex = tick_add_ifset(now_ms, s->rep->wto);
Willy Tarreau91861262007-10-17 17:06:05 +020055 s->cli_state = CL_STSHUTR;
56 buffer_flush(s->rep);
57 if (msg && msg->len)
58 buffer_write(s->rep, msg->str, msg->len);
59 s->req->l = 0;
60}
61
62
63/*
64 * returns a message into the rep buffer, and flushes the req buffer.
65 * The reply buffer doesn't need to be empty before this. The message
66 * is contained in a "chunk". If it is null, then an empty message is
67 * used.
68 */
69void client_return(struct session *s, const struct chunk *msg)
70{
71 buffer_flush(s->rep);
72 if (msg && msg->len)
73 buffer_write(s->rep, msg->str, msg->len);
74 s->req->l = 0;
75}
76
77/*
78 * Local variables:
79 * c-indent-level: 8
80 * c-basic-offset: 8
81 * End:
82 */