/[pengfork]/pengfork/src/engine.c
ViewVC logotype

Diff of /pengfork/src/engine.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by chupa, Tue Sep 10 13:17:22 2002 UTC revision 1.7 by chupa, Wed Sep 11 15:39:32 2002 UTC
# Line 43  struct Line 43  struct
43    int fd;    int fd;
44    buffer_t in;    buffer_t in;
45    buffer_t out;    buffer_t out;
46      int timeout;
47      int last_timeout;
48    time_t lastread;    time_t lastread;
49    struct engine_functions fn;    struct engine_functions fn;
50  }  }
# Line 59  engine_init () Line 61  engine_init ()
61    for (i = 0; i < MAX_CLIENTS; i++)    for (i = 0; i < MAX_CLIENTS; i++)
62      {      {
63        client[i].fd = -1;        client[i].fd = -1;
64          client[i].timeout = 0;
65          client[i].last_timeout = 0;
66        client[i].fn.init = NULL;        client[i].fn.init = NULL;
67        client[i].fn.want_read = NULL;        client[i].fn.want_read = NULL;
68        client[i].fn.want_write = NULL;        client[i].fn.want_write = NULL;
# Line 120  engine_loop () Line 124  engine_loop ()
124            /*            /*
125             * There was no data to read/write             * There was no data to read/write
126             */             */
           engine_timeout ();  
127            debug (1, "engine - Timed out\n");            debug (1, "engine - Timed out\n");
128              engine_timeout ();
129          }          }
130      }      }
131  }  }
# Line 133  engine_stop () Line 137  engine_stop ()
137  }  }
138    
139  void  void
140  engine_register (fd, fn)  engine_register (fd, timeout, fn)
141       int fd;       int fd;
142         int timeout;
143       struct engine_functions fn;       struct engine_functions fn;
144  {  {
145    int index = nbclients;    int index = nbclients;
# Line 164  engine_register (fd, fn) Line 169  engine_register (fd, fn)
169    
170    /* Fill structure */    /* Fill structure */
171    client[index].fd = fd;    client[index].fd = fd;
172      client[index].timeout = timeout;
173      client[index].last_timeout = 0;
174    client[index].fn = fn;    client[index].fn = fn;
175    init_buffer (&client[index].in);    init_buffer (&client[index].in);
176    init_buffer (&client[index].out);    init_buffer (&client[index].out);
# Line 195  engine_unregister (fd) Line 202  engine_unregister (fd)
202    if (index < nbclients - 1)    if (index < nbclients - 1)
203      {      {
204        /* Shift all next clients */        /* Shift all next clients */
205        memcpy (&client[index], &client[index + 1],        memmove (&client[index], &client[index + 1],
206                (nbclients - index) * sizeof (client[0]));               (nbclients - index) * sizeof (client[0]));
207      }      }
208    
209    nbclients--;    nbclients--;
# Line 225  engine_set_readers (fdset, maxfd) Line 232  engine_set_readers (fdset, maxfd)
232              }              }
233          }          }
234        else        else
235          /* Normally the input buffer mustn't be full */          {
236          log (LOG_ERR, "engine - An input buffer is full\n");          /* Normally the input buffer mustn't be full */
237            log (LOG_ERR, "engine - An input buffer is full\n");
238            buffer_free(&client[i].in,client[i].in.used);
239            debug( 1, "\tBuffer flushed\n",i);
240            }
241      }      }
242  }  }
243    
# Line 262  engine_read (fdset) Line 273  engine_read (fdset)
273        if (FD_ISSET (client[i].fd, fdset))        if (FD_ISSET (client[i].fd, fdset))
274          {          {
275          client[i].lastread = time(NULL);          client[i].lastread = time(NULL);
276            client[i].last_timeout = 0;
277            /* Fill buffer with available data */            /* Fill buffer with available data */
278            buffer_recv (&client[i].in, client[i].fd);            buffer_recv (&client[i].in, client[i].fd);
           /* And ask the client to treat the buffer */  
           if (client[i].fn.readfn != NULL)  
             client[i].fn.readfn (&client[i].in);  
279          }          }
280          /* And ask the client to treat the buffer */
281          if (client[i].in.used > 0 && client[i].fn.readfn != NULL)
282            client[i].fn.readfn (&client[i].in);
283      }      }
284  }  }
285    
# Line 293  engine_write (fdset) Line 305  engine_write (fdset)
305  void  void
306  engine_timeout ()  engine_timeout ()
307  {  {
308    /*    int i, nb;
309     * UNIMPLEMENTED do not use timeouts    time_t t = time(NULL);
    */  
   int i;  
310    
311    for (i = 0; i < nbclients; i++)    for (i = 0; i < nbclients; i++)
312      {      {
313        if (client[i].fn.timeoutfn != NULL)        /* Client want timeout notification ? */
314          client[i].fn.timeoutfn (&client[i].in, &client[i].out, 1);        if (client[i].fn.timeoutfn != NULL && client[i].timeout > 0)
315            {
316            /* Is the client in timeout ? */
317            if(t - client[i].lastread >= client[i].timeout)
318              {
319                nb=(t - client[i].lastread)/client[i].timeout;
320                /* How many timeouts had happened ? */
321                if(nb > client[i].last_timeout)
322                  {
323                    client[i].last_timeout = nb;
324                    client[i].fn.timeoutfn (&client[i].in, &client[i].out,
325                                      t - client[i].lastread);
326                  }
327              }
328            }
329      }      }
330  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26