$search
00001 /* 00002 * Event loop 00003 * Copyright (c) 2002-2006, Jouni Malinen <j@w1.fi> 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 * 00014 * This file defines an event loop interface that supports processing events 00015 * from registered timeouts (i.e., do something after N seconds), sockets 00016 * (e.g., a new packet available for reading), and signals. eloop.c is an 00017 * implementation of this interface using select() and sockets. This is 00018 * suitable for most UNIX/POSIX systems. When porting to other operating 00019 * systems, it may be necessary to replace that implementation with OS specific 00020 * mechanisms. 00021 */ 00022 00023 #ifndef ELOOP_H 00024 #define ELOOP_H 00025 00029 #define ELOOP_ALL_CTX (void *) -1 00030 00037 typedef enum { 00038 EVENT_TYPE_READ = 0, 00039 EVENT_TYPE_WRITE, 00040 EVENT_TYPE_EXCEPTION 00041 } eloop_event_type; 00042 00049 typedef void (*eloop_sock_handler)(int sock, void *eloop_ctx, void *sock_ctx); 00050 00056 typedef void (*eloop_event_handler)(void *eloop_data, void *user_ctx); 00057 00063 typedef void (*eloop_timeout_handler)(void *eloop_data, void *user_ctx); 00064 00072 typedef void (*eloop_signal_handler)(int sig, void *signal_ctx); 00073 00080 int eloop_init(void); 00081 00096 int eloop_register_read_sock(int sock, eloop_sock_handler handler, 00097 void *eloop_data, void *user_data); 00098 00106 void eloop_unregister_read_sock(int sock); 00107 00123 int eloop_register_sock(int sock, eloop_event_type type, 00124 eloop_sock_handler handler, 00125 void *eloop_data, void *user_data); 00126 00135 void eloop_unregister_sock(int sock, eloop_event_type type); 00136 00159 int eloop_register_event(void *event, size_t event_size, 00160 eloop_event_handler handler, 00161 void *eloop_data, void *user_data); 00162 00171 void eloop_unregister_event(void *event, size_t event_size); 00172 00185 int eloop_register_timeout(unsigned int secs, unsigned int usecs, 00186 eloop_timeout_handler handler, 00187 void *eloop_data, void *user_data); 00188 00200 int eloop_cancel_timeout(eloop_timeout_handler handler, 00201 void *eloop_data, void *user_data); 00202 00213 int eloop_is_timeout_registered(eloop_timeout_handler handler, 00214 void *eloop_data, void *user_data); 00215 00229 int eloop_register_signal(int sig, eloop_signal_handler handler, 00230 void *user_data); 00231 00249 int eloop_register_signal_terminate(eloop_signal_handler handler, 00250 void *user_data); 00251 00269 int eloop_register_signal_reconfig(eloop_signal_handler handler, 00270 void *user_data); 00271 00279 void eloop_run(void); 00280 00287 void eloop_terminate(void); 00288 00295 void eloop_destroy(void); 00296 00306 int eloop_terminated(void); 00307 00314 void eloop_wait_for_read_sock(int sock); 00315 00316 #endif /* ELOOP_H */