pazpar2  1.13.0
eventl.h
Go to the documentation of this file.
1 /* This file is part of Pazpar2.
2  Copyright (C) Index Data
3 
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8 
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 */
19 
20 #ifndef EVENTL_H
21 #define EVENTL_H
22 
23 #include <time.h>
24 
25 struct iochan;
26 
27 typedef void (*IOC_CALLBACK)(struct iochan *i, int event);
28 
29 typedef struct iochan_man_s *iochan_man_t;
30 
31 typedef struct iochan
32 {
33  int fd;
34  int flags;
35 #define EVENT_INPUT 0x01
36 #define EVENT_OUTPUT 0x02
37 #define EVENT_EXCEPT 0x04
38 #define EVENT_TIMEOUT 0x08
40  void *data;
41  int destroyed;
42  time_t last_event;
43  time_t max_idle;
46 
47  iochan_man_t man;
48  char *name;
49  struct iochan *next;
51 } *IOCHAN;
52 
53 
54 iochan_man_t iochan_man_create(int no_threads, int max_sockets);
55 int iochan_add(iochan_man_t man, IOCHAN chan, int slack);
56 void iochan_man_events(iochan_man_t man);
57 void iochan_man_destroy(iochan_man_t *mp);
58 void iochan_destroy(IOCHAN chan);
59 
60 #define iochan_getfd(i) ((i)->fd)
61 #define iochan_setfd(i, d) ((i)->fd = d)
62 #define iochan_getdata(i) ((i)->data)
63 #define iochan_setdata(i, d) ((i)->data = d)
64 #define iochan_setflags(i, d) ((i)->flags = d)
65 #define iochan_setflag(i, d) ((i)->flags |= d)
66 #define iochan_clearflag(i, d) ((i)->flags &= ~(d))
67 #define iochan_getflag(i, d) ((i)->flags & d ? 1 : 0)
68 #define iochan_settimeout(i, t) ((i)->max_idle = (t), (i)->last_event = time(0))
69 #define iochan_activity(i) ((i)->last_event = time(0))
70 
71 IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name);
72 
73 #endif
74 /*
75  * Local variables:
76  * c-basic-offset: 4
77  * c-file-style: "Stroustrup"
78  * indent-tabs-mode: nil
79  * End:
80  * vim: shiftwidth=4 tabstop=8 expandtab
81  */
82 
iochan_man_t man
Definition: eventl.h:47
struct iochan * IOCHAN
void * data
Definition: eventl.h:40
time_t max_idle
Definition: eventl.h:43
int poll_offset
Definition: eventl.h:50
char * name
Definition: eventl.h:48
IOC_CALLBACK fun
Definition: eventl.h:39
int this_event
Definition: eventl.h:44
int iochan_add(iochan_man_t man, IOCHAN chan, int slack)
Definition: eventl.c:173
void iochan_man_events(iochan_man_t man)
Definition: eventl.c:433
iochan_man_t iochan_man_create(int no_threads, int max_sockets)
Definition: eventl.c:113
void iochan_man_destroy(iochan_man_t *mp)
Definition: eventl.c:152
struct iochan * next
Definition: eventl.h:49
int fd
Definition: eventl.h:33
int flags
Definition: eventl.h:34
void(* IOC_CALLBACK)(struct iochan *i, int event)
Definition: eventl.h:27
Definition: eventl.h:31
int thread_users
Definition: eventl.h:45
time_t last_event
Definition: eventl.h:42
struct iochan_man_s * iochan_man_t
Definition: eventl.h:29
int destroyed
Definition: eventl.h:41
void iochan_destroy(IOCHAN chan)
Definition: eventl.c:201
IOCHAN iochan_create(int fd, IOC_CALLBACK cb, int flags, const char *name)
Definition: eventl.c:209