Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | b277d6e | 2012-05-11 16:59:14 +0200 | [diff] [blame] | 2 | * Functions used to send/receive data using SOCK_STREAM sockets. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | b277d6e | 2012-05-11 16:59:14 +0200 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
Willy Tarreau | 6b4aad4 | 2009-01-18 21:59:13 +0100 | [diff] [blame] | 13 | #define _GNU_SOURCE |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 14 | #include <errno.h> |
| 15 | #include <fcntl.h> |
| 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | |
| 19 | #include <sys/socket.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 23 | #include <netinet/tcp.h> |
| 24 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 25 | #include <common/buffer.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 26 | #include <common/compat.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 27 | #include <common/config.h> |
Willy Tarreau | d6f087e | 2008-01-18 17:20:13 +0100 | [diff] [blame] | 28 | #include <common/debug.h> |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 29 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 30 | #include <common/ticks.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 31 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | |
Willy Tarreau | 8b11708 | 2012-08-06 15:06:49 +0200 | [diff] [blame] | 33 | #include <proto/connection.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 34 | #include <proto/fd.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 35 | #include <proto/freq_ctr.h> |
| 36 | #include <proto/log.h> |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 37 | #include <proto/pipe.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 38 | #include <proto/raw_sock.h> |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 39 | #include <proto/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <proto/task.h> |
| 41 | |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 42 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | b277d6e | 2012-05-11 16:59:14 +0200 | [diff] [blame] | 44 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 45 | #if defined(CONFIG_HAP_LINUX_SPLICE) |
Willy Tarreau | 43d8fb2 | 2011-08-22 17:12:02 +0200 | [diff] [blame] | 46 | #include <common/splice.h> |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 47 | |
| 48 | /* A pipe contains 16 segments max, and it's common to see segments of 1448 bytes |
| 49 | * because of timestamps. Use this as a hint for not looping on splice(). |
| 50 | */ |
| 51 | #define SPLICE_FULL_HINT 16*1448 |
| 52 | |
Willy Tarreau | a9de333 | 2009-11-28 07:47:10 +0100 | [diff] [blame] | 53 | /* how many data we attempt to splice at once when the buffer is configured for |
| 54 | * infinite forwarding */ |
| 55 | #define MAX_SPLICE_AT_ONCE (1<<30) |
| 56 | |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 57 | /* Returns : |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 58 | * -1 if splice() is not supported |
| 59 | * >= 0 to report the amount of spliced bytes. |
| 60 | * connection flags are updated (error, read0, wait_room, wait_data). |
| 61 | * The caller must have previously allocated the pipe. |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 62 | */ |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 63 | int raw_sock_to_pipe(struct connection *conn, struct pipe *pipe, unsigned int count) |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 64 | { |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 65 | static int splice_detects_close; |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 66 | int ret; |
Willy Tarreau | afad0e0 | 2012-08-09 14:45:22 +0200 | [diff] [blame] | 67 | int retval = 0; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 68 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 69 | /* Under Linux, if FD_POLL_HUP is set, we have reached the end. |
| 70 | * Since older splice() implementations were buggy and returned |
| 71 | * EAGAIN on end of read, let's bypass the call to splice() now. |
| 72 | */ |
| 73 | if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_IN|FD_POLL_HUP)) == FD_POLL_HUP) |
| 74 | goto out_read0; |
Willy Tarreau | a9de333 | 2009-11-28 07:47:10 +0100 | [diff] [blame] | 75 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 76 | while (count) { |
| 77 | if (count > MAX_SPLICE_AT_ONCE) |
| 78 | count = MAX_SPLICE_AT_ONCE; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 79 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 80 | ret = splice(conn->t.sock.fd, NULL, pipe->prod, NULL, count, |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 81 | SPLICE_F_MOVE|SPLICE_F_NONBLOCK); |
| 82 | |
| 83 | if (ret <= 0) { |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 84 | if (ret == 0) { |
Willy Tarreau | 98b306b | 2009-01-25 11:11:32 +0100 | [diff] [blame] | 85 | /* connection closed. This is only detected by |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 86 | * recent kernels (>= 2.6.27.13). If we notice |
| 87 | * it works, we store the info for later use. |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 88 | */ |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 89 | splice_detects_close = 1; |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 90 | goto out_read0; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | if (errno == EAGAIN) { |
| 94 | /* there are two reasons for EAGAIN : |
| 95 | * - nothing in the socket buffer (standard) |
| 96 | * - pipe is full |
Willy Tarreau | 98b306b | 2009-01-25 11:11:32 +0100 | [diff] [blame] | 97 | * - the connection is closed (kernel < 2.6.27.13) |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 98 | * The last case is annoying but know if we can detect it |
| 99 | * and if we can't then we rely on the call to recv() to |
| 100 | * get a valid verdict. The difference between the first |
| 101 | * two situations is problematic. Since we don't know if |
| 102 | * the pipe is full, we'll stop if the pipe is not empty. |
| 103 | * Anyway, we will almost always fill/empty the pipe. |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 104 | */ |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 105 | if (pipe->data) { |
| 106 | /* alway stop reading until the pipe is flushed */ |
| 107 | conn->flags |= CO_FL_WAIT_ROOM; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 111 | /* We don't know if the connection was closed, |
| 112 | * but if we know splice detects close, then we |
| 113 | * know it for sure. |
Willy Tarreau | 98b306b | 2009-01-25 11:11:32 +0100 | [diff] [blame] | 114 | * But if we're called upon POLLIN with an empty |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 115 | * pipe and get EAGAIN, it is suspect enough to |
Willy Tarreau | 98b306b | 2009-01-25 11:11:32 +0100 | [diff] [blame] | 116 | * try to fall back to the normal recv scheme |
| 117 | * which will be able to deal with the situation. |
| 118 | */ |
Willy Tarreau | 82a0456 | 2011-12-11 22:37:06 +0100 | [diff] [blame] | 119 | if (splice_detects_close) |
Willy Tarreau | 56a77e5 | 2012-09-02 18:34:44 +0200 | [diff] [blame] | 120 | __conn_data_poll_recv(conn); /* we know for sure that it's EAGAIN */ |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 121 | break; |
| 122 | } |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 123 | else if (errno == ENOSYS || errno == EINVAL) { |
| 124 | /* splice not supported on this end, disable it. |
| 125 | * We can safely return -1 since there is no |
| 126 | * chance that any data has been piped yet. |
| 127 | */ |
Willy Tarreau | dc340a9 | 2009-06-28 23:10:19 +0200 | [diff] [blame] | 128 | return -1; |
| 129 | } |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 130 | else if (errno == EINTR) { |
| 131 | /* try again */ |
| 132 | continue; |
| 133 | } |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 134 | /* here we have another error */ |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 135 | conn->flags |= CO_FL_ERROR; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 136 | break; |
| 137 | } /* ret <= 0 */ |
| 138 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 139 | retval += ret; |
| 140 | pipe->data += ret; |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 141 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 142 | if (pipe->data >= SPLICE_FULL_HINT || ret >= global.tune.recv_enough) { |
| 143 | /* We've read enough of it for this time, let's stop before |
| 144 | * being asked to poll. |
| 145 | */ |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | } /* while */ |
| 149 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 150 | return retval; |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 151 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 152 | out_read0: |
| 153 | conn_sock_read0(conn); |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 154 | return retval; |
| 155 | } |
| 156 | |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 157 | /* Send as many bytes as possible from the pipe to the connection's socket. |
| 158 | */ |
| 159 | int raw_sock_from_pipe(struct connection *conn, struct pipe *pipe) |
| 160 | { |
| 161 | int ret, done; |
| 162 | |
| 163 | done = 0; |
| 164 | while (pipe->data) { |
| 165 | ret = splice(pipe->cons, NULL, conn->t.sock.fd, NULL, pipe->data, |
| 166 | SPLICE_F_MOVE|SPLICE_F_NONBLOCK); |
| 167 | |
| 168 | if (ret <= 0) { |
| 169 | if (ret == 0 || errno == EAGAIN) { |
Willy Tarreau | 56a77e5 | 2012-09-02 18:34:44 +0200 | [diff] [blame] | 170 | __conn_data_poll_send(conn); |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 171 | break; |
| 172 | } |
| 173 | else if (errno == EINTR) |
| 174 | continue; |
| 175 | |
| 176 | /* here we have another error */ |
| 177 | conn->flags |= CO_FL_ERROR; |
| 178 | break; |
| 179 | } |
| 180 | |
| 181 | done += ret; |
| 182 | pipe->data -= ret; |
| 183 | } |
| 184 | return done; |
| 185 | } |
| 186 | |
Willy Tarreau | 6b4aad4 | 2009-01-18 21:59:13 +0100 | [diff] [blame] | 187 | #endif /* CONFIG_HAP_LINUX_SPLICE */ |
| 188 | |
| 189 | |
Willy Tarreau | 2ba4465 | 2012-08-20 17:30:32 +0200 | [diff] [blame] | 190 | /* Receive up to <count> bytes from connection <conn>'s socket and store them |
| 191 | * into buffer <buf>. The caller must ensure that <count> is always smaller |
| 192 | * than the buffer's size. Only one call to recv() is performed, unless the |
| 193 | * buffer wraps, in which case a second call may be performed. The connection's |
| 194 | * flags are updated with whatever special event is detected (error, read0, |
| 195 | * empty). The caller is responsible for taking care of those events and |
| 196 | * avoiding the call if inappropriate. The function does not call the |
| 197 | * connection's polling update function, so the caller is responsible for this. |
| 198 | */ |
| 199 | static int raw_sock_to_buf(struct connection *conn, struct buffer *buf, int count) |
| 200 | { |
| 201 | int ret, done = 0; |
| 202 | int try = count; |
| 203 | |
| 204 | /* stop here if we reached the end of data */ |
| 205 | if ((fdtab[conn->t.sock.fd].ev & (FD_POLL_IN|FD_POLL_HUP)) == FD_POLL_HUP) |
| 206 | goto read0; |
| 207 | |
| 208 | /* compute the maximum block size we can read at once. */ |
| 209 | if (buffer_empty(buf)) { |
| 210 | /* let's realign the buffer to optimize I/O */ |
| 211 | buf->p = buf->data; |
| 212 | } |
| 213 | else if (buf->data + buf->o < buf->p && |
| 214 | buf->p + buf->i < buf->data + buf->size) { |
| 215 | /* remaining space wraps at the end, with a moving limit */ |
| 216 | if (try > buf->data + buf->size - (buf->p + buf->i)) |
| 217 | try = buf->data + buf->size - (buf->p + buf->i); |
| 218 | } |
| 219 | |
| 220 | /* read the largest possible block. For this, we perform only one call |
| 221 | * to recv() unless the buffer wraps and we exactly fill the first hunk, |
| 222 | * in which case we accept to do it once again. A new attempt is made on |
| 223 | * EINTR too. |
| 224 | */ |
| 225 | while (try) { |
| 226 | ret = recv(conn->t.sock.fd, bi_end(buf), try, 0); |
| 227 | |
| 228 | if (ret > 0) { |
| 229 | buf->i += ret; |
| 230 | done += ret; |
| 231 | if (ret < try) { |
| 232 | /* unfortunately, on level-triggered events, POLL_HUP |
| 233 | * is generally delivered AFTER the system buffer is |
| 234 | * empty, so this one might never match. |
| 235 | */ |
| 236 | if (fdtab[conn->t.sock.fd].ev & FD_POLL_HUP) |
| 237 | goto read0; |
| 238 | break; |
| 239 | } |
| 240 | count -= ret; |
| 241 | try = count; |
| 242 | } |
| 243 | else if (ret == 0) { |
| 244 | goto read0; |
| 245 | } |
| 246 | else if (errno == EAGAIN) { |
Willy Tarreau | 56a77e5 | 2012-09-02 18:34:44 +0200 | [diff] [blame] | 247 | __conn_data_poll_recv(conn); |
Willy Tarreau | 2ba4465 | 2012-08-20 17:30:32 +0200 | [diff] [blame] | 248 | break; |
| 249 | } |
| 250 | else if (errno != EINTR) { |
| 251 | conn->flags |= CO_FL_ERROR; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | return done; |
| 256 | |
| 257 | read0: |
| 258 | conn_sock_read0(conn); |
| 259 | return done; |
| 260 | } |
| 261 | |
| 262 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 263 | /* Send all pending bytes from buffer <buf> to connection <conn>'s socket. |
| 264 | * <flags> may contain MSG_MORE to make the system hold on without sending |
| 265 | * data too fast. |
| 266 | * Only one call to send() is performed, unless the buffer wraps, in which case |
| 267 | * a second call may be performed. The connection's flags are updated with |
| 268 | * whatever special event is detected (error, empty). The caller is responsible |
| 269 | * for taking care of those events and avoiding the call if inappropriate. The |
| 270 | * function does not call the connection's polling update function, so the caller |
| 271 | * is responsible for this. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 272 | */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 273 | static int raw_sock_from_buf(struct connection *conn, struct buffer *buf, int flags) |
Willy Tarreau | 0c2fc1f | 2009-01-18 15:30:37 +0100 | [diff] [blame] | 274 | { |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 275 | int ret, try, done, send_flag; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 276 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 277 | done = 0; |
| 278 | /* send the largest possible block. For this we perform only one call |
| 279 | * to send() unless the buffer wraps and we exactly fill the first hunk, |
| 280 | * in which case we accept to do it once again. |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 281 | */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 282 | while (buf->o) { |
| 283 | try = buf->o; |
Willy Tarreau | 89fa706 | 2012-03-02 16:13:16 +0100 | [diff] [blame] | 284 | /* outgoing data may wrap at the end */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 285 | if (buf->data + try > buf->p) |
| 286 | try = buf->data + try - buf->p; |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 287 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 288 | send_flag = MSG_DONTWAIT | MSG_NOSIGNAL; |
| 289 | if (try < buf->o) |
| 290 | send_flag = MSG_MORE; |
Willy Tarreau | fb14edc | 2009-06-14 15:24:37 +0200 | [diff] [blame] | 291 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 292 | ret = send(conn->t.sock.fd, bo_ptr(buf), try, send_flag | flags); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 293 | |
| 294 | if (ret > 0) { |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 295 | buf->o -= ret; |
| 296 | done += ret; |
Willy Tarreau | b38903c | 2008-11-23 21:33:29 +0100 | [diff] [blame] | 297 | |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 298 | if (likely(!buffer_len(buf))) |
Willy Tarreau | 0c2fc1f | 2009-01-18 15:30:37 +0100 | [diff] [blame] | 299 | /* optimize data alignment in the buffer */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 300 | buf->p = buf->data; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 301 | |
Willy Tarreau | ab3e1d3 | 2007-06-03 14:10:36 +0200 | [diff] [blame] | 302 | /* if the system buffer is full, don't insist */ |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 303 | if (ret < try) |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 304 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 305 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 306 | else if (ret == 0 || errno == EAGAIN) { |
Willy Tarreau | 0c2fc1f | 2009-01-18 15:30:37 +0100 | [diff] [blame] | 307 | /* nothing written, we need to poll for write first */ |
Willy Tarreau | 56a77e5 | 2012-09-02 18:34:44 +0200 | [diff] [blame] | 308 | __conn_data_poll_send(conn); |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 309 | break; |
Willy Tarreau | 8374918 | 2007-04-15 20:56:27 +0200 | [diff] [blame] | 310 | } |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 311 | else if (errno != EINTR) { |
| 312 | conn->flags |= CO_FL_ERROR; |
| 313 | break; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 314 | } |
Willy Tarreau | 5368d80 | 2012-08-21 18:22:06 +0200 | [diff] [blame] | 315 | } |
| 316 | return done; |
Willy Tarreau | 0c2fc1f | 2009-01-18 15:30:37 +0100 | [diff] [blame] | 317 | } |
Willy Tarreau | 6996e15 | 2007-04-30 14:37:43 +0200 | [diff] [blame] | 318 | |
Willy Tarreau | 0c2fc1f | 2009-01-18 15:30:37 +0100 | [diff] [blame] | 319 | |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 320 | /* data-layer operations for RAW sockets */ |
| 321 | struct data_ops raw_sock = { |
| 322 | .snd_buf = raw_sock_from_buf, |
| 323 | .rcv_buf = raw_sock_to_buf, |
Willy Tarreau | 96199b1 | 2012-08-24 00:46:52 +0200 | [diff] [blame] | 324 | #if defined(CONFIG_HAP_LINUX_SPLICE) |
| 325 | .rcv_pipe = raw_sock_to_pipe, |
| 326 | .snd_pipe = raw_sock_from_pipe, |
| 327 | #endif |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 328 | .shutr = NULL, |
| 329 | .shutw = NULL, |
| 330 | .close = NULL, |
Willy Tarreau | 5c979a9 | 2012-05-07 17:15:39 +0200 | [diff] [blame] | 331 | }; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 332 | |
| 333 | /* |
| 334 | * Local variables: |
| 335 | * c-indent-level: 8 |
| 336 | * c-basic-offset: 8 |
| 337 | * End: |
| 338 | */ |