1 /* 2 * Copyright (c) 2006, Stefan Walter 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above 10 * copyright notice, this list of conditions and the 11 * following disclaimer. 12 * * Redistributions in binary form must reproduce the 13 * above copyright notice, this list of conditions and 14 * the following disclaimer in the documentation and/or 15 * other materials provided with the distribution. 16 * * The names of contributors to this software may not be 17 * used to endorse or promote products derived from this 18 * software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 31 * DAMAGE. 32 */ 33 34 #ifndef __SERVER_MAINLOOP_H__ 35 #define __SERVER_MAINLOOP_H__ 36 37 #include <stdint.h> 38 39 #define SERVER_READ 0x01 40 #define SERVER_WRITE 0x02 41 42 typedef void (*server_socket_callback)(int fd, int type, void* arg); 43 typedef int (*server_timer_callback)(uint64_t when, void* arg); 44 45 void server_init(); 46 void server_uninit(); 47 int server_run(); 48 void server_stop(); 49 int server_stopped(); 50 int server_watch(int fd, int type, server_socket_callback callback, void* arg); 51 void server_unwatch(int fd); 52 int server_timer(int length, server_timer_callback callback, void* arg); 53 int server_timer_at(struct timeval, int, server_timer_callback, void*); 54 uint64_t server_get_time(); 55 56 #endif /* __SERVER_MAINLOOP_H__ */ 57