blob: de8280bd0657829aa607ec2fa5a975e3a419f449 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Client-side variables and functions.
3 *
4 * Copyright 2000-2006 Willy Tarreau <w@1wt.eu>
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
13#include <errno.h>
14#include <fcntl.h>
15#include <stdio.h>
16#include <stdlib.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020017#include <string.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020018
19#include <sys/socket.h>
20#include <sys/stat.h>
21#include <sys/types.h>
22
Willy Tarreau2dd0d472006-06-29 17:53:05 +020023#include <common/compat.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020024#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020025#include <common/time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020026
27#include <types/backend.h>
28#include <types/buffers.h>
29#include <types/global.h>
30#include <types/httperr.h>
31#include <types/polling.h>
32#include <types/proxy.h>
33#include <types/server.h>
34#include <types/session.h>
35
Willy Tarreau54469402006-07-29 16:59:06 +020036#include <proto/buffers.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020037#include <proto/client.h>
38#include <proto/fd.h>
39#include <proto/log.h>
Willy Tarreaue5f20dc2006-12-03 15:21:35 +010040#include <proto/hdr_idx.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020041#include <proto/proto_http.h>
42#include <proto/stream_sock.h>
43#include <proto/task.h>
44
45
46
47/*
48 * FIXME: This should move to the STREAM_SOCK code then split into TCP and HTTP.
49 */
50
51/*
52 * this function is called on a read event from a listen socket, corresponding
53 * to an accept. It tries to accept as many connections as possible.
54 * It returns 0.
55 */
56int event_accept(int fd) {
57 struct proxy *p = (struct proxy *)fdtab[fd].owner;
58 struct session *s;
Willy Tarreauc2168d32007-03-03 20:51:44 +010059 struct http_txn *txn;
Willy Tarreaubaaee002006-06-26 02:48:02 +020060 struct task *t;
61 int cfd;
62 int max_accept;
63
64 if (global.nbproc > 1)
65 max_accept = 8; /* let other processes catch some connections too */
66 else
67 max_accept = -1;
68
Willy Tarreauf1221aa2006-12-17 22:14:12 +010069 while (p->feconn < p->maxconn && max_accept--) {
Willy Tarreaubaaee002006-06-26 02:48:02 +020070 struct sockaddr_storage addr;
71 socklen_t laddr = sizeof(addr);
72
73 if ((cfd = accept(fd, (struct sockaddr *)&addr, &laddr)) == -1) {
74 switch (errno) {
75 case EAGAIN:
76 case EINTR:
77 case ECONNABORTED:
78 return 0; /* nothing more to accept */
79 case ENFILE:
80 send_log(p, LOG_EMERG,
81 "Proxy %s reached system FD limit at %d. Please check system tunables.\n",
82 p->id, maxfd);
83 return 0;
84 case EMFILE:
85 send_log(p, LOG_EMERG,
86 "Proxy %s reached process FD limit at %d. Please check 'ulimit-n' and restart.\n",
87 p->id, maxfd);
88 return 0;
89 case ENOBUFS:
90 case ENOMEM:
91 send_log(p, LOG_EMERG,
92 "Proxy %s reached system memory limit at %d sockets. Please check system tunables.\n",
93 p->id, maxfd);
94 return 0;
95 default:
96 return 0;
97 }
98 }
99
100 if ((s = pool_alloc(session)) == NULL) { /* disable this proxy for a while */
101 Alert("out of memory in event_accept().\n");
Willy Tarreau2a429502006-10-15 14:52:29 +0200102 MY_FD_CLR(fd, StaticReadEvent);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200103 p->state = PR_STIDLE;
104 close(cfd);
105 return 0;
106 }
107
108 /* if this session comes from a known monitoring system, we want to ignore
109 * it as soon as possible, which means closing it immediately for TCP.
110 */
111 s->flags = 0;
112 if (addr.ss_family == AF_INET &&
113 p->mon_mask.s_addr &&
114 (((struct sockaddr_in *)&addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr) {
115 if (p->mode == PR_MODE_TCP) {
116 close(cfd);
117 pool_free(session, s);
118 continue;
119 }
120 s->flags |= SN_MONITOR;
121 }
122
123 if ((t = pool_alloc(task)) == NULL) { /* disable this proxy for a while */
124 Alert("out of memory in event_accept().\n");
Willy Tarreau2a429502006-10-15 14:52:29 +0200125 MY_FD_CLR(fd, StaticReadEvent);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200126 p->state = PR_STIDLE;
127 close(cfd);
128 pool_free(session, s);
129 return 0;
130 }
131
132 s->cli_addr = addr;
133 if (cfd >= global.maxsock) {
134 Alert("accept(): not enough free sockets. Raise -n argument. Giving up.\n");
135 close(cfd);
136 pool_free(task, t);
137 pool_free(session, s);
138 return 0;
139 }
140
141 if ((fcntl(cfd, F_SETFL, O_NONBLOCK) == -1) ||
142 (setsockopt(cfd, IPPROTO_TCP, TCP_NODELAY,
143 (char *) &one, sizeof(one)) == -1)) {
144 Alert("accept(): cannot set the socket in non blocking mode. Giving up\n");
145 close(cfd);
146 pool_free(task, t);
147 pool_free(session, s);
148 return 0;
149 }
150
151 if (p->options & PR_O_TCP_CLI_KA)
152 setsockopt(cfd, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(one));
153
Willy Tarreau964c9362007-01-07 00:38:00 +0100154 t->wq = NULL;
155 t->rqnext = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200156 t->state = TASK_IDLE;
157 t->process = process_session;
158 t->context = s;
159
160 s->task = t;
Willy Tarreau830ff452006-12-17 19:31:23 +0100161 s->be = s->fe = p;
Willy Tarreau73de9892006-11-30 11:40:23 +0100162
Willy Tarreaubaaee002006-06-26 02:48:02 +0200163 s->cli_state = (p->mode == PR_MODE_HTTP) ? CL_STHEADERS : CL_STDATA; /* no HTTP headers for non-HTTP proxies */
164 s->srv_state = SV_STIDLE;
165 s->req = s->rep = NULL; /* will be allocated later */
166
Willy Tarreaubaaee002006-06-26 02:48:02 +0200167 s->cli_fd = cfd;
168 s->srv_fd = -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200169 s->srv = NULL;
170 s->pend_pos = NULL;
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200171 s->conn_retries = p->conn_retries;
Willy Tarreauddb358d2006-12-17 22:55:52 +0100172
173 /* FIXME: the logs are horribly complicated now, because they are
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200174 * defined in <p>, <p>, and later <be> and <be>.
Willy Tarreauddb358d2006-12-17 22:55:52 +0100175 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200176
177 if (s->flags & SN_MONITOR)
178 s->logs.logwait = 0;
179 else
180 s->logs.logwait = p->to_log;
181
182 s->logs.tv_accept = now;
183 s->logs.t_request = -1;
184 s->logs.t_queue = -1;
185 s->logs.t_connect = -1;
186 s->logs.t_data = -1;
187 s->logs.t_close = 0;
Willy Tarreau35d66b02007-01-02 00:28:21 +0100188 s->logs.bytes_in = s->logs.bytes_out = 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200189 s->logs.prx_queue_size = 0; /* we get the number of pending conns before us */
190 s->logs.srv_queue_size = 0; /* we will get this number soon */
191
192 s->data_source = DATA_SRC_NONE;
193
194 s->uniq_id = totalconn;
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100195 p->cum_feconn++; /* cum_beconn will be increased once assigned */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200196
Willy Tarreauc2168d32007-03-03 20:51:44 +0100197 txn = &s->txn;
Willy Tarreau3d300592007-03-18 18:34:41 +0100198 txn->flags = 0;
Willy Tarreau042cc792007-03-19 16:20:06 +0100199 /* Those variables will be checked and freed if non-NULL in
200 * session.c:session_free(). It is important that they are
201 * properly initialized.
202 */
203 txn->srv_cookie = NULL;
204 txn->cli_cookie = NULL;
205 txn->uri = NULL;
Willy Tarreauc2168d32007-03-03 20:51:44 +0100206 txn->req.cap = NULL;
207 txn->rsp.cap = NULL;
208 txn->hdr_idx.v = NULL;
209 txn->hdr_idx.size = txn->hdr_idx.used = 0;
Willy Tarreau45e73e32006-12-17 00:05:15 +0100210
211 if (p->mode == PR_MODE_HTTP) {
Willy Tarreau3bac9ff2007-03-18 17:31:28 +0100212 txn->status = -1;
213
Willy Tarreauc2168d32007-03-03 20:51:44 +0100214 txn->req.msg_state = HTTP_MSG_RQBEFORE; /* at the very beginning of the request */
215 txn->req.sol = txn->req.eol = NULL;
216 txn->req.som = txn->req.eoh = 0; /* relative to the buffer */
217 txn->auth_hdr.len = -1;
Willy Tarreau45e73e32006-12-17 00:05:15 +0100218
Willy Tarreauc2168d32007-03-03 20:51:44 +0100219 txn->hdr_idx.size = MAX_HTTP_HDR;
Willy Tarreau45e73e32006-12-17 00:05:15 +0100220
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200221 if (p->nb_req_cap > 0) {
Willy Tarreauc2168d32007-03-03 20:51:44 +0100222 if ((txn->req.cap =
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200223 pool_alloc_from(p->req_cap_pool, p->nb_req_cap*sizeof(char *)))
Willy Tarreau45e73e32006-12-17 00:05:15 +0100224 == NULL) { /* no memory */
225 close(cfd); /* nothing can be done for this fd without memory */
226 pool_free(task, t);
227 pool_free(session, s);
228 return 0;
229 }
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200230 memset(txn->req.cap, 0, p->nb_req_cap*sizeof(char *));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200231 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200232
Willy Tarreau45e73e32006-12-17 00:05:15 +0100233
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200234 if (p->nb_rsp_cap > 0) {
Willy Tarreauc2168d32007-03-03 20:51:44 +0100235 if ((txn->rsp.cap =
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200236 pool_alloc_from(p->rsp_cap_pool, p->nb_rsp_cap*sizeof(char *)))
Willy Tarreau45e73e32006-12-17 00:05:15 +0100237 == NULL) { /* no memory */
Willy Tarreauc2168d32007-03-03 20:51:44 +0100238 if (txn->req.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200239 pool_free_to(p->req_cap_pool, txn->req.cap);
Willy Tarreau45e73e32006-12-17 00:05:15 +0100240 close(cfd); /* nothing can be done for this fd without memory */
241 pool_free(task, t);
242 pool_free(session, s);
243 return 0;
244 }
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200245 memset(txn->rsp.cap, 0, p->nb_rsp_cap*sizeof(char *));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200246 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200247
Willy Tarreau45e73e32006-12-17 00:05:15 +0100248
Willy Tarreauc2168d32007-03-03 20:51:44 +0100249 if ((txn->hdr_idx.v =
250 pool_alloc_from(p->hdr_idx_pool, txn->hdr_idx.size*sizeof(*txn->hdr_idx.v)))
Willy Tarreaue5f20dc2006-12-03 15:21:35 +0100251 == NULL) { /* no memory */
Willy Tarreauc2168d32007-03-03 20:51:44 +0100252 if (txn->rsp.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200253 pool_free_to(p->rsp_cap_pool, txn->rsp.cap);
Willy Tarreauc2168d32007-03-03 20:51:44 +0100254 if (txn->req.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200255 pool_free_to(p->req_cap_pool, txn->req.cap);
Willy Tarreaue5f20dc2006-12-03 15:21:35 +0100256 close(cfd); /* nothing can be done for this fd without memory */
257 pool_free(task, t);
258 pool_free(session, s);
259 return 0;
260 }
Willy Tarreauc2168d32007-03-03 20:51:44 +0100261 hdr_idx_init(&txn->hdr_idx);
Willy Tarreaue5f20dc2006-12-03 15:21:35 +0100262 }
263
Willy Tarreaubaaee002006-06-26 02:48:02 +0200264 if ((p->mode == PR_MODE_TCP || p->mode == PR_MODE_HTTP)
265 && (p->logfac1 >= 0 || p->logfac2 >= 0)) {
266 struct sockaddr_storage sockname;
267 socklen_t namelen = sizeof(sockname);
268
269 if (addr.ss_family != AF_INET ||
Willy Tarreau73de9892006-11-30 11:40:23 +0100270 !(s->fe->options & PR_O_TRANSP) ||
Willy Tarreaubaaee002006-06-26 02:48:02 +0200271 get_original_dst(cfd, (struct sockaddr_in *)&sockname, &namelen) == -1)
272 getsockname(cfd, (struct sockaddr *)&sockname, &namelen);
273
274 if (p->to_log) {
275 /* we have the client ip */
276 if (s->logs.logwait & LW_CLIP)
277 if (!(s->logs.logwait &= ~LW_CLIP))
Willy Tarreau42250582007-04-01 01:30:43 +0200278 tcp_sess_log(s);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200279 }
280 else if (s->cli_addr.ss_family == AF_INET) {
281 char pn[INET_ADDRSTRLEN], sn[INET_ADDRSTRLEN];
282 if (inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)&sockname)->sin_addr,
283 sn, sizeof(sn)) &&
284 inet_ntop(AF_INET, (const void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr,
285 pn, sizeof(pn))) {
286 send_log(p, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
287 pn, ntohs(((struct sockaddr_in *)&s->cli_addr)->sin_port),
288 sn, ntohs(((struct sockaddr_in *)&sockname)->sin_port),
289 p->id, (p->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
290 }
291 }
292 else {
293 char pn[INET6_ADDRSTRLEN], sn[INET6_ADDRSTRLEN];
294 if (inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)&sockname)->sin6_addr,
295 sn, sizeof(sn)) &&
296 inet_ntop(AF_INET6, (const void *)&((struct sockaddr_in6 *)&s->cli_addr)->sin6_addr,
297 pn, sizeof(pn))) {
298 send_log(p, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
299 pn, ntohs(((struct sockaddr_in6 *)&s->cli_addr)->sin6_port),
300 sn, ntohs(((struct sockaddr_in6 *)&sockname)->sin6_port),
301 p->id, (p->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
302 }
303 }
304 }
305
306 if ((global.mode & MODE_DEBUG) && (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))) {
307 struct sockaddr_in sockname;
308 socklen_t namelen = sizeof(sockname);
309 int len;
310 if (addr.ss_family != AF_INET ||
Willy Tarreau73de9892006-11-30 11:40:23 +0100311 !(s->fe->options & PR_O_TRANSP) ||
Willy Tarreaubaaee002006-06-26 02:48:02 +0200312 get_original_dst(cfd, (struct sockaddr_in *)&sockname, &namelen) == -1)
313 getsockname(cfd, (struct sockaddr *)&sockname, &namelen);
314
315 if (s->cli_addr.ss_family == AF_INET) {
316 char pn[INET_ADDRSTRLEN];
317 inet_ntop(AF_INET,
318 (const void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr,
319 pn, sizeof(pn));
320
321 len = sprintf(trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n",
322 s->uniq_id, p->id, (unsigned short)fd, (unsigned short)cfd,
323 pn, ntohs(((struct sockaddr_in *)&s->cli_addr)->sin_port));
324 }
325 else {
326 char pn[INET6_ADDRSTRLEN];
327 inet_ntop(AF_INET6,
328 (const void *)&((struct sockaddr_in6 *)(&s->cli_addr))->sin6_addr,
329 pn, sizeof(pn));
330
331 len = sprintf(trash, "%08x:%s.accept(%04x)=%04x from [%s:%d]\n",
332 s->uniq_id, p->id, (unsigned short)fd, (unsigned short)cfd,
333 pn, ntohs(((struct sockaddr_in6 *)(&s->cli_addr))->sin6_port));
334 }
335
336 write(1, trash, len);
337 }
338
339 if ((s->req = pool_alloc(buffer)) == NULL) { /* no memory */
Willy Tarreauc2168d32007-03-03 20:51:44 +0100340 if (txn->hdr_idx.v != NULL)
341 pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
342 if (txn->rsp.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200343 pool_free_to(p->rsp_cap_pool, txn->rsp.cap);
Willy Tarreauc2168d32007-03-03 20:51:44 +0100344 if (txn->req.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200345 pool_free_to(p->req_cap_pool, txn->req.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200346 close(cfd); /* nothing can be done for this fd without memory */
347 pool_free(task, t);
348 pool_free(session, s);
349 return 0;
350 }
351
Willy Tarreau54469402006-07-29 16:59:06 +0200352 buffer_init(s->req);
353 s->req->rlim += BUFSIZE;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200354 if (s->cli_state == CL_STHEADERS) /* reserve some space for header rewriting */
355 s->req->rlim -= MAXREWRITE;
356
Willy Tarreau73de9892006-11-30 11:40:23 +0100357 s->req->rto = s->fe->clitimeout;
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200358 s->req->wto = s->be->srvtimeout;
359 s->req->cto = s->be->srvtimeout;
Willy Tarreaud7971282006-07-29 18:36:34 +0200360
Willy Tarreaubaaee002006-06-26 02:48:02 +0200361 if ((s->rep = pool_alloc(buffer)) == NULL) { /* no memory */
362 pool_free(buffer, s->req);
Willy Tarreauc2168d32007-03-03 20:51:44 +0100363 if (txn->hdr_idx.v != NULL)
364 pool_free_to(p->hdr_idx_pool, txn->hdr_idx.v);
365 if (txn->rsp.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200366 pool_free_to(p->rsp_cap_pool, txn->rsp.cap);
Willy Tarreauc2168d32007-03-03 20:51:44 +0100367 if (txn->req.cap != NULL)
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200368 pool_free_to(p->req_cap_pool, txn->req.cap);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200369 close(cfd); /* nothing can be done for this fd without memory */
370 pool_free(task, t);
371 pool_free(session, s);
372 return 0;
373 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200374
Willy Tarreau54469402006-07-29 16:59:06 +0200375 buffer_init(s->rep);
376
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200377 s->rep->rto = s->be->srvtimeout;
Willy Tarreau830ff452006-12-17 19:31:23 +0100378 s->rep->wto = s->fe->clitimeout;
Willy Tarreaud7971282006-07-29 18:36:34 +0200379 s->rep->cto = 0;
380
Willy Tarreaubaaee002006-06-26 02:48:02 +0200381 fdtab[cfd].owner = t;
382 fdtab[cfd].state = FD_STREADY;
Willy Tarreaud7971282006-07-29 18:36:34 +0200383 fdtab[cfd].cb[DIR_RD].f = &stream_sock_read;
Willy Tarreau54469402006-07-29 16:59:06 +0200384 fdtab[cfd].cb[DIR_RD].b = s->req;
Willy Tarreauf8306d52006-07-29 19:01:31 +0200385 fdtab[cfd].cb[DIR_WR].f = &stream_sock_write;
Willy Tarreau54469402006-07-29 16:59:06 +0200386 fdtab[cfd].cb[DIR_WR].b = s->rep;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200387
388 if ((p->mode == PR_MODE_HTTP && (s->flags & SN_MONITOR)) ||
Willy Tarreau0f772532006-12-23 20:51:41 +0100389 (p->mode == PR_MODE_HEALTH && (p->options & PR_O_HTTP_CHK))) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200390 /* Either we got a request from a monitoring system on an HTTP instance,
391 * or we're in health check mode with the 'httpchk' option enabled. In
392 * both cases, we return a fake "HTTP/1.0 200 OK" response and we exit.
393 */
Willy Tarreau0f772532006-12-23 20:51:41 +0100394 struct chunk msg = { .str = "HTTP/1.0 200 OK\r\n\r\n", .len = 19 };
395 client_retnclose(s, &msg); /* forge a 200 response */
396 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200397 else if (p->mode == PR_MODE_HEALTH) { /* health check mode, no client reading */
Willy Tarreau0f772532006-12-23 20:51:41 +0100398 struct chunk msg = { .str = "OK\n", .len = 3 };
399 client_retnclose(s, &msg); /* forge an "OK" response */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200400 }
401 else {
Willy Tarreau2a429502006-10-15 14:52:29 +0200402 MY_FD_SET(cfd, StaticReadEvent);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200403 }
404
405#if defined(DEBUG_FULL) && defined(ENABLE_EPOLL)
406 if (PrevReadEvent) {
Willy Tarreau2a429502006-10-15 14:52:29 +0200407 assert(!(MY_FD_ISSET(cfd, PrevReadEvent)));
408 assert(!(MY_FD_ISSET(cfd, PrevWriteEvent)));
Willy Tarreaubaaee002006-06-26 02:48:02 +0200409 }
410#endif
411 fd_insert(cfd);
412
Willy Tarreaud7971282006-07-29 18:36:34 +0200413 tv_eternity(&s->req->rex);
414 tv_eternity(&s->req->wex);
415 tv_eternity(&s->req->cex);
416 tv_eternity(&s->rep->rex);
417 tv_eternity(&s->rep->wex);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200418
Willy Tarreau73de9892006-11-30 11:40:23 +0100419 if (s->fe->clitimeout) {
Willy Tarreau2a429502006-10-15 14:52:29 +0200420 if (MY_FD_ISSET(cfd, StaticReadEvent))
Willy Tarreau73de9892006-11-30 11:40:23 +0100421 tv_delayfrom(&s->req->rex, &now, s->fe->clitimeout);
Willy Tarreau2a429502006-10-15 14:52:29 +0200422 if (MY_FD_ISSET(cfd, StaticWriteEvent))
Willy Tarreau73de9892006-11-30 11:40:23 +0100423 tv_delayfrom(&s->rep->wex, &now, s->fe->clitimeout);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200424 }
425
Willy Tarreaud7971282006-07-29 18:36:34 +0200426 tv_min(&t->expire, &s->req->rex, &s->rep->wex);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200427
428 task_queue(t);
429
430 if (p->mode != PR_MODE_HEALTH)
431 task_wakeup(&rq, t);
432
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100433 p->feconn++; /* beconn will be increased later */
434 if (p->feconn > p->feconn_max)
435 p->feconn_max = p->feconn;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200436 actconn++;
437 totalconn++;
438
439 // fprintf(stderr, "accepting from %p => %d conn, %d total, task=%p\n", p, actconn, totalconn, t);
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100440 } /* end of while (p->feconn < p->maxconn) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200441 return 0;
442}
443
444
445
446/*
447 * Local variables:
448 * c-indent-level: 8
449 * c-basic-offset: 8
450 * End:
451 */