Implemented session timeout; ping command
[pazpar2-moved-to-github.git] / eventl.h
1 /*
2  * Copyright (c) 1995-1999, Index Data
3  * See the file LICENSE for details.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: eventl.h,v $
7  * Revision 1.3  2006-12-12 02:36:24  quinn
8  * Implemented session timeout; ping command
9  *
10  * Revision 1.2  2006/11/18 05:00:38  quinn
11  * Added record retrieval, etc.
12  *
13  * Revision 1.1.1.1  2006/11/14 20:44:38  quinn
14  * PazPar2
15  *
16  * Revision 1.1.1.1  2000/02/23 14:40:18  heikki
17  * Original import to cvs
18  *
19  * Revision 1.11  1999/04/20 09:56:48  adam
20  * Added 'name' paramter to encoder/decoder routines (typedef Odr_fun).
21  * Modified all encoders/decoders to reflect this change.
22  *
23  * Revision 1.10  1998/01/29 13:30:23  adam
24  * Better event handle system for NT/Unix.
25  *
26  * Revision 1.9  1997/09/01 09:31:48  adam
27  * Removed definition statserv_remove from statserv.h to eventl.h.
28  *
29  * Revision 1.8  1995/06/19 12:39:09  quinn
30  * Fixed bug in timeout code. Added BER dumper.
31  *
32  * Revision 1.7  1995/06/16  10:31:34  quinn
33  * Added session timeout.
34  *
35  * Revision 1.6  1995/05/16  08:51:02  quinn
36  * License, documentation, and memory fixes
37  *
38  * Revision 1.5  1995/05/15  11:56:37  quinn
39  * Asynchronous facilities. Restructuring of seshigh code.
40  *
41  * Revision 1.4  1995/03/27  08:34:23  quinn
42  * Added dynamic server functionality.
43  * Released bindings to session.c (is now redundant)
44  *
45  * Revision 1.3  1995/03/15  08:37:42  quinn
46  * Now we're pretty much set for nonblocking I/O.
47  *
48  * Revision 1.2  1995/03/14  10:28:00  quinn
49  * More work on demo server.
50  *
51  * Revision 1.1  1995/03/10  18:22:45  quinn
52  * The rudiments of an asynchronous server.
53  *
54  */
55
56 #ifndef EVENTL_H
57 #define EVENTL_H
58
59 #include <time.h>
60
61 struct iochan;
62
63 typedef void (*IOC_CALLBACK)(struct iochan *i, int event);
64
65 typedef struct iochan
66 {
67     int fd;
68     int flags;
69 #define EVENT_INPUT     0x01
70 #define EVENT_OUTPUT    0x02
71 #define EVENT_EXCEPT    0x04
72 #define EVENT_TIMEOUT   0x08
73 #define EVENT_WORK      0x10
74     int force_event;
75     IOC_CALLBACK fun;
76     void *data;
77     int destroyed;
78     time_t last_event;
79     time_t max_idle;
80     
81     struct iochan *next;
82 } *IOCHAN;
83
84 #define iochan_destroy(i) (void)((i)->destroyed = 1)
85 #define iochan_getfd(i) ((i)->fd)
86 #define iochan_setfd(i, f) ((i)->fd = (f))
87 #define iochan_getdata(i) ((i)->data)
88 #define iochan_setdata(i, d) ((i)->data = d)
89 #define iochan_getflags(i) ((i)->flags)
90 #define iochan_setflags(i, d) ((i)->flags = d)
91 #define iochan_setflag(i, d) ((i)->flags |= d)
92 #define iochan_clearflag(i, d) ((i)->flags &= ~(d))
93 #define iochan_getflag(i, d) ((i)->flags & d ? 1 : 0)
94 #define iochan_getfun(i) ((i)->fun)
95 #define iochan_setfun(i, d) ((i)->fun = d)
96 #define iochan_setevent(i, e) ((i)->force_event = (e))
97 #define iochan_getnext(i) ((i)->next)
98 #define iochan_settimeout(i, t) ((i)->max_idle = (t), (i)->last_event = time(0))
99 #define iochan_activity(i) ((i)->last_event = time(0))
100
101 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags);
102 int event_loop(IOCHAN *iochans);
103
104 #endif