blob: dea2c9674dde66555213dd4c2eb8dff3ea0dd17a [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{
Willy Tarreaufa7e1022008-10-19 07:30:41 +020051 //FIXME: must move to lower level
52 //EV_FD_CLR(s->cli_fd, DIR_RD);
53 //EV_FD_SET(s->cli_fd, DIR_WR);
54 buffer_abort(s->req);
55
Willy Tarreau1ae3a052008-08-16 10:56:30 +020056 s->cli_state = CL_STSHUTR; // FIXME: still used by unix sockets
Willy Tarreau91861262007-10-17 17:06:05 +020057 buffer_flush(s->rep);
Willy Tarreaufa7e1022008-10-19 07:30:41 +020058 buffer_shutr_now(s->rep);
Willy Tarreau91861262007-10-17 17:06:05 +020059 if (msg && msg->len)
60 buffer_write(s->rep, msg->str, msg->len);
Willy Tarreaufa7e1022008-10-19 07:30:41 +020061
62 s->rep->wex = tick_add_ifset(now_ms, s->rep->wto);
63 s->rep->flags |= BF_MAY_FORWARD;
Willy Tarreau91861262007-10-17 17:06:05 +020064}
65
66
67/*
68 * returns a message into the rep buffer, and flushes the req buffer.
69 * The reply buffer doesn't need to be empty before this. The message
70 * is contained in a "chunk". If it is null, then an empty message is
71 * used.
72 */
73void client_return(struct session *s, const struct chunk *msg)
74{
Willy Tarreaue393fe22008-08-16 22:18:07 +020075 buffer_flush(s->req);
Willy Tarreau91861262007-10-17 17:06:05 +020076 buffer_flush(s->rep);
77 if (msg && msg->len)
78 buffer_write(s->rep, msg->str, msg->len);
Willy Tarreau91861262007-10-17 17:06:05 +020079}
80
81/*
82 * Local variables:
83 * c-indent-level: 8
84 * c-basic-offset: 8
85 * End:
86 */