1c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* 2c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu> 3c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * All rights reserved. 4c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * 5c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * Redistribution and use in source and binary forms, with or without 6c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * modification, are permitted provided that the following conditions 7c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * are met: 8c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * 1. Redistributions of source code must retain the above copyright 9c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * notice, this list of conditions and the following disclaimer. 10c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * 2. Redistributions in binary form must reproduce the above copyright 11c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * notice, this list of conditions and the following disclaimer in the 12c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * documentation and/or other materials provided with the distribution. 13c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * 3. The name of the author may not be used to endorse or promote products 14c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * derived from this software without specific prior written permission. 15c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * 16c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott */ 27c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef _EVENT_INTERNAL_H_ 28c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define _EVENT_INTERNAL_H_ 29c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 30c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifdef __cplusplus 31c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottextern "C" { 32c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif 33c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 34c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "config.h" 35c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "min_heap.h" 36c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#include "evsignal.h" 37c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 38c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstruct eventop { 39c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott const char *name; 40c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void *(*init)(struct event_base *); 41c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int (*add)(void *, struct event *); 42c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int (*del)(void *, struct event *); 43c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int (*dispatch)(struct event_base *, void *, struct timeval *); 44c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void (*dealloc)(struct event_base *, void *); 45c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /* set if we need to reinitialize the event base */ 46c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int need_reinit; 47c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 48c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 49c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottstruct event_base { 50c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott const struct eventop *evsel; 51c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void *evbase; 52c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int event_count; /* counts number of total events */ 53c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int event_count_active; /* counts number of active events */ 54c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 55c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int event_gotterm; /* Set to terminate loop */ 56c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int event_break; /* Set to terminate loop immediately */ 57c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 58c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /* active event management */ 59c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct event_list **activequeues; 60c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott int nactivequeues; 61c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 62c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott /* signal handling info */ 63c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct evsignal_info sig; 64c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 65c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct event_list eventqueue; 66c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct timeval event_tv; 67c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 68c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct min_heap timeheap; 69c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 70c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott struct timeval tv_cache; 71c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott}; 72c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 73c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* Internal use only: Functions that might be missing from <sys/queue.h> */ 74c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifndef HAVE_TAILQFOREACH 75c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define TAILQ_FIRST(head) ((head)->tqh_first) 76c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define TAILQ_END(head) NULL 77c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) 78c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define TAILQ_FOREACH(var, head, field) \ 79c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott for((var) = TAILQ_FIRST(head); \ 80c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott (var) != TAILQ_END(head); \ 81c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott (var) = TAILQ_NEXT(var, field)) 82c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ 83c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ 84c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott (elm)->field.tqe_next = (listelm); \ 85c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott *(listelm)->field.tqe_prev = (elm); \ 86c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ 87c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} while (0) 88c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif /* TAILQ_FOREACH */ 89c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 90c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottint _evsignal_set_handler(struct event_base *base, int evsignal, 91c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott void (*fn)(int)); 92c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottint _evsignal_restore_handler(struct event_base *base, int evsignal); 93c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 94c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott/* defined in evutil.c */ 95c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scottconst char *evutil_getenv(const char *varname); 96c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 97c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#ifdef __cplusplus 98c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott} 99c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif 100c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott 101c7f5f8508d98d5952d42ed7648c2a8f30a4da156Patrick Scott#endif /* _EVENT_INTERNAL_H_ */ 102