Initial revision
[silc.git] / lib / silccore / silcschedule.h
1 /*
2
3   silcschedule.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1998 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef SILCSCHEDULE_H
22 #define SILCSCHEDULE_H
23
24 /* Structure holding list of file descriptors, scheduler is supposed to
25    be listenning. The max_fd field is the maximum number of possible file
26    descriptors in the list. This value is set at the initialization
27    of the scheduler and it usually is the maximum number of connections 
28    allowed. */
29 typedef struct {
30   int *fd;
31   unsigned int last_fd;
32   unsigned int max_fd;
33 } SilcScheduleFdList;
34
35 /* 
36    Silc Schedule object. 
37
38    This is the actual schedule object in Silc. Both Silc client and server 
39    uses this same scheduler. Actually, this scheduler could be used by any
40    program needing scheduling.
41
42    Following short description of the fields:
43
44    SilcTaskQueue fd_queue
45
46        Task queue hook for non-timeout tasks. Usually this means that these
47        tasks perform different kind of I/O on file descriptors. File 
48        descriptors are usually network sockets but they actually can be
49        any file descriptors. This hook is initialized in silc_schedule_init
50        function. Timeout tasks should not be added to this queue because
51        they will never expire.
52
53    SilcTaskQueue timeout_queue
54
55        Task queue hook for timeout tasks. This hook is reserved specificly
56        for tasks with timeout. Non-timeout tasks should not be added to this
57        queue because they will never get scheduled. This hook is also
58        initialized in silc_schedule_init function.
59
60    SilcTaskQueue generic_queue
61
62        Task queue hook for generic tasks. This hook is reserved specificly
63        for generic tasks, tasks that apply to all file descriptors, except
64        to those that have specificly registered a non-timeout task. This hook
65        is also initialized in silc_schedule_init function.
66
67    SilcScheduleFdList fd_list
68
69        List of file descriptors the scheduler is supposed to be listenning.
70        This is updated internally.
71
72    struct timeval *timeout;
73
74        Pointer to the schedules next timeout. Value of this timeout is
75        automatically updated in the silc_schedule function.
76
77    int valid
78
79        Marks validity of the scheduler. This is a boolean value. When this
80        is false the scheduler is terminated and the program will end. This
81        set to true when the scheduler is initialized with silc_schedule_init
82        function.
83
84    fd_set in
85    fd_set out
86
87        File descriptor sets for select(). These are automatically managed
88        by the scheduler and should not be touched otherwise.
89
90    int max_fd
91
92        Number of maximum file descriptors for select(). This, as well, is
93        managed automatically by the scheduler and should be considered to 
94        be read-only field otherwise.
95
96 */
97
98 typedef struct {
99   SilcTaskQueue fd_queue;
100   SilcTaskQueue timeout_queue;
101   SilcTaskQueue generic_queue;
102   SilcScheduleFdList fd_list;
103   struct timeval *timeout;
104   int valid;
105   fd_set in;
106   fd_set out;
107   int max_fd;
108 } SilcScheduleObject;
109
110 typedef SilcScheduleObject SilcSchedule;
111
112 /* Prototypes */
113 void silc_schedule_init(SilcTaskQueue fd_queue,
114                         SilcTaskQueue timeout_queue,
115                         SilcTaskQueue generic_queue,
116                         int max_fd);
117 int silc_schedule_uninit();
118 void silc_schedule_stop();
119 void silc_schedule_set_listen_fd(int fd, unsigned int iomask);
120 void silc_schedule_unset_listen_fd(int fd);
121 void silc_schedule();
122
123 #endif