Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Helper functions to send data over a socket and buffer. |
| 3 | * Should probably move somewhere else, but where ? |
| 4 | * |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 5 | * Copyright 2000-2008 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 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> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 31 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 32 | #include <common/time.h> |
| 33 | #include <common/version.h> |
| 34 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #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 | */ |
| 49 | void 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 Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 54 | s->rep->wex = tick_add_ifset(now_ms, s->rep->wto); |
Willy Tarreau | adfb856 | 2008-08-11 15:24:42 +0200 | [diff] [blame] | 55 | s->rep->flags |= BF_MAY_FORWARD; |
Willy Tarreau | 1ae3a05 | 2008-08-16 10:56:30 +0200 | [diff] [blame] | 56 | s->cli_state = CL_STSHUTR; // FIXME: still used by unix sockets |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 57 | buffer_flush(s->rep); |
| 58 | if (msg && msg->len) |
| 59 | buffer_write(s->rep, msg->str, msg->len); |
| 60 | s->req->l = 0; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | * returns a message into the rep buffer, and flushes the req buffer. |
| 66 | * The reply buffer doesn't need to be empty before this. The message |
| 67 | * is contained in a "chunk". If it is null, then an empty message is |
| 68 | * used. |
| 69 | */ |
| 70 | void client_return(struct session *s, const struct chunk *msg) |
| 71 | { |
| 72 | buffer_flush(s->rep); |
| 73 | if (msg && msg->len) |
| 74 | buffer_write(s->rep, msg->str, msg->len); |
| 75 | s->req->l = 0; |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Local variables: |
| 80 | * c-indent-level: 8 |
| 81 | * c-basic-offset: 8 |
| 82 | * End: |
| 83 | */ |