20 |
* |
* |
21 |
*/ |
*/ |
22 |
|
|
23 |
|
#include "config.h" |
24 |
|
|
25 |
#include <sys/time.h> |
#include <sys/time.h> |
26 |
#include <sys/types.h> |
#include <sys/types.h> |
27 |
#include <netinet/in.h> |
#include <netinet/in.h> |
30 |
#include <stdio.h> |
#include <stdio.h> |
31 |
#include <time.h> |
#include <time.h> |
32 |
|
|
33 |
|
#include "gettext.h" |
34 |
#include "log.h" |
#include "log.h" |
35 |
#include "access.h" |
#include "access.h" |
36 |
#include "if.h" |
#include "if.h" |
90 |
struct timeval tv; |
struct timeval tv; |
91 |
int fds; |
int fds; |
92 |
|
|
93 |
while (!exiting || nbclients>0) |
while (!exiting || nbclients > 0) |
94 |
{ |
{ |
95 |
FD_ZERO (&rfdset); |
FD_ZERO (&rfdset); |
96 |
FD_ZERO (&wfdset); |
FD_ZERO (&wfdset); |
105 |
* well... in fact this should not happen |
* well... in fact this should not happen |
106 |
* or very rarely |
* or very rarely |
107 |
*/ |
*/ |
108 |
log (LOG_WARNING, "engine - No data to wait\n"); |
log (LOG_WARNING, gettext ("engine - No data to wait\n")); |
109 |
sleep (ENGINE_TIMEOUT); |
sleep (ENGINE_TIMEOUT); |
110 |
fds = 0; /* simulate a timeout */ |
fds = 0; /* simulate a timeout */ |
111 |
} |
} |
130 |
debug (9, "engine - Timed out\n"); |
debug (9, "engine - Timed out\n"); |
131 |
engine_timeout (); |
engine_timeout (); |
132 |
} |
} |
133 |
if(exiting && nbclients>0) |
if (exiting && nbclients > 0) |
134 |
engine_end_clients (); |
engine_end_clients (); |
135 |
} |
} |
136 |
debug (1, "engine - ended\n"); |
debug (1, "engine - ended\n"); |
209 |
{ |
{ |
210 |
/* Shift all next clients */ |
/* Shift all next clients */ |
211 |
memmove (&client[index], &client[index + 1], |
memmove (&client[index], &client[index + 1], |
212 |
(nbclients - index) * sizeof (client[0])); |
(nbclients - index) * sizeof (client[0])); |
213 |
} |
} |
214 |
|
|
215 |
nbclients--; |
nbclients--; |
239 |
} |
} |
240 |
else |
else |
241 |
{ |
{ |
242 |
/* Normally the input buffer mustn't be full */ |
/* Normally the input buffer mustn't be full */ |
243 |
log (LOG_ERR, "engine - An input buffer is full\n"); |
log (LOG_ERR, gettext ("engine - An input buffer is full\n")); |
244 |
buffer_free(&client[i].in,client[i].in.used); |
buffer_free (&client[i].in, client[i].in.used); |
245 |
debug( 1, "\tBuffer flushed\n",i); |
debug (1, "\tBuffer flushed\n", i); |
246 |
} |
} |
247 |
} |
} |
248 |
} |
} |
257 |
for (i = 0; i < nbclients; i++) |
for (i = 0; i < nbclients; i++) |
258 |
{ |
{ |
259 |
if (client[i].fn.want_write == NULL || |
if (client[i].fn.want_write == NULL || |
260 |
client[i].fn.want_write (&client[i].out)) |
client[i].fn.want_write (&client[i].out)) |
261 |
{ |
{ |
262 |
if (client[i].out.used > 0) |
if (client[i].out.used > 0) |
263 |
{ |
{ |
264 |
FD_SET (client[i].fd, fdset); |
FD_SET (client[i].fd, fdset); |
265 |
*maxfd = MAX (*maxfd, client[i].fd); |
*maxfd = MAX (*maxfd, client[i].fd); |
266 |
} |
} |
267 |
} |
} |
268 |
} |
} |
269 |
} |
} |
278 |
{ |
{ |
279 |
if (FD_ISSET (client[i].fd, fdset)) |
if (FD_ISSET (client[i].fd, fdset)) |
280 |
{ |
{ |
281 |
client[i].lastread = time(NULL); |
client[i].lastread = time (NULL); |
282 |
client[i].last_timeout = 0; |
client[i].last_timeout = 0; |
283 |
/* Fill buffer with available data */ |
/* Fill buffer with available data */ |
284 |
buffer_recv (&client[i].in, client[i].fd); |
buffer_recv (&client[i].in, client[i].fd); |
285 |
} |
} |
312 |
engine_timeout () |
engine_timeout () |
313 |
{ |
{ |
314 |
int i, nb; |
int i, nb; |
315 |
time_t t = time(NULL); |
time_t t = time (NULL); |
316 |
|
|
317 |
for (i = 0; i < nbclients; i++) |
for (i = 0; i < nbclients; i++) |
318 |
{ |
{ |
319 |
/* Client want timeout notification ? */ |
/* Client want timeout notification ? */ |
320 |
if (client[i].fn.timeoutfn != NULL && client[i].timeout > 0) |
if (client[i].fn.timeoutfn != NULL && client[i].timeout > 0) |
321 |
{ |
{ |
322 |
/* Is the client in timeout ? */ |
/* Is the client in timeout ? */ |
323 |
if(t - client[i].lastread >= client[i].timeout) |
if (t - client[i].lastread >= client[i].timeout) |
324 |
{ |
{ |
325 |
nb=(t - client[i].lastread)/client[i].timeout; |
nb = (t - client[i].lastread) / client[i].timeout; |
326 |
/* How many timeouts had happened ? */ |
/* How many timeouts had happened ? */ |
327 |
if(nb > client[i].last_timeout) |
if (nb > client[i].last_timeout) |
328 |
{ |
{ |
329 |
client[i].last_timeout = nb; |
client[i].last_timeout = nb; |
330 |
client[i].fn.timeoutfn (&client[i].in, &client[i].out, |
client[i].fn.timeoutfn (&client[i].in, &client[i].out, |
331 |
t - client[i].lastread); |
t - client[i].lastread); |
332 |
} |
} |
333 |
} |
} |
334 |
} |
} |
335 |
} |
} |
336 |
} |
} |
344 |
{ |
{ |
345 |
if (client[i].fn.end != NULL) |
if (client[i].fn.end != NULL) |
346 |
{ |
{ |
347 |
if(client[i].fn.end(&client[i].in, &client[i].out)) |
if (client[i].fn.end (&client[i].in, &client[i].out)) |
348 |
engine_unregister(client[i--].fd); |
engine_unregister (client[i--].fd); |
349 |
} |
} |
350 |
else |
else |
351 |
engine_unregister(client[i--].fd); |
engine_unregister (client[i--].fd); |
352 |
} |
} |
353 |
} |
} |