5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1998 - 2000 Pekka Riikonen
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.
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.
21 #ifndef SILCSCHEDULE_H
22 #define SILCSCHEDULE_H
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
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.
42 Following short description of the fields:
44 SilcTaskQueue fd_queue
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.
53 SilcTaskQueue timeout_queue
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.
60 SilcTaskQueue generic_queue
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.
67 SilcScheduleFdList fd_list
69 List of file descriptors the scheduler is supposed to be listenning.
70 This is updated internally.
72 struct timeval *timeout;
74 Pointer to the schedules next timeout. Value of this timeout is
75 automatically updated in the silc_schedule function.
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
87 File descriptor sets for select(). These are automatically managed
88 by the scheduler and should not be touched otherwise.
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.
99 SilcTaskQueue fd_queue;
100 SilcTaskQueue timeout_queue;
101 SilcTaskQueue generic_queue;
102 SilcScheduleFdList fd_list;
103 struct timeval *timeout;
108 } SilcScheduleObject;
110 typedef SilcScheduleObject SilcSchedule;
113 void silc_schedule_init(SilcTaskQueue *fd_queue,
114 SilcTaskQueue *timeout_queue,
115 SilcTaskQueue *generic_queue,
117 int silc_schedule_uninit();
118 void silc_schedule_stop();
119 void silc_schedule_set_listen_fd(int fd, uint32 iomask);
120 void silc_schedule_unset_listen_fd(int fd);
121 void silc_schedule();
122 int silc_schedule_one(int block);