From: Wouter Wijngaards Date: Tue, 23 Jan 2007 16:10:23 +0000 (+0000) Subject: Work on doxygen attr_unused, library searches at end (so size_t exists and so X-Git-Tag: release-0.0~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9e14cba23b62f6e591800899c14fea4bb28eb9f;p=thirdparty%2Funbound.git Work on doxygen attr_unused, library searches at end (so size_t exists and so on) and netevent nicer. git-svn-id: file:///svn/unbound/trunk@29 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/configure.ac b/configure.ac index bbe353908..36450c054 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,7 @@ CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"]) CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"]) CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"]) CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"]) +CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"]) AC_C_INLINE AC_DEFUN([AC_CHECK_FORMAT_ATTRIBUTE], @@ -90,6 +91,69 @@ fi AC_CHECK_FORMAT_ATTRIBUTE AC_CHECK_UNUSED_ATTRIBUTE +if test "$srcdir" != "."; then + CPPFLAGS="$CPPFLAGS -I$srcdir"; +fi + +# Use libtool +AC_CHECK_PROGS(libtool, [glibtool libtool15 libtool], [./libtool]) +AC_PATH_TOOL(AR, ar, [false]) +if test $AR = false; then + AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) +fi +AC_CHECK_PROG(doxygen, doxygen, doxygen) +# avoid libtool max commandline length test on systems that fork slowly. +AC_CANONICAL_HOST +if echo "$host_os" | grep "sunos4" >/dev/null; then + lt_cv_sys_max_cmd_len=32750; +fi +AC_PROG_LIBTOOL + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([getopt.h stdarg.h stdbool.h openssl/ssl.h netinet/in.h time.h sys/param.h sys/socket.h],,, [AC_INCLUDES_DEFAULT]) + +# check for types +AC_CHECK_TYPE(int8_t, char) +AC_CHECK_TYPE(int16_t, short) +AC_CHECK_TYPE(int32_t, int) +AC_CHECK_TYPE(int64_t, long long) +AC_CHECK_TYPE(uint8_t, unsigned char) +AC_CHECK_TYPE(uint16_t, unsigned short) +AC_CHECK_TYPE(uint32_t, unsigned int) +AC_CHECK_TYPE(uint64_t, unsigned long long) +AC_TYPE_SIZE_T +AC_CHECK_TYPE(ssize_t, int) +AC_TYPE_UID_T +AC_TYPE_PID_T +AC_TYPE_OFF_T + +AC_CHECK_TYPE(socklen_t, , + [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ +AC_INCLUDES_DEFAULT +#if HAVE_SYS_SOCKET_H +# include +#endif +]) +AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ +AC_INCLUDES_DEFAULT +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_NETINET_IN_H +# include +#endif +]) +AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ +AC_INCLUDES_DEFAULT +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_NETINET_IN_H +# include +#endif +]) + # Checks for libraries. AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname], [enable SSL (will check /usr/local/ssl @@ -156,65 +220,6 @@ AC_ARG_WITH(ssl, AC_HELP_STRING([--with-libevent=pathname], AC_SUBST(RUNTIME_PATH) fi -if test "$srcdir" != "."; then - CPPFLAGS="$CPPFLAGS -I$srcdir"; -fi - -# Use libtool -AC_CHECK_PROGS(libtool, [glibtool libtool15 libtool], [./libtool]) -AC_PATH_TOOL(AR, ar, [false]) -if test $AR = false; then - AC_MSG_ERROR([Cannot find 'ar', please extend PATH to include it]) -fi -AC_CHECK_PROG(doxygen, doxygen, doxygen) -# avoid libtool max commandline length test on systems that fork slowly. -AC_CANONICAL_HOST -if echo "$host_os" | grep "sunos4" >/dev/null; then - lt_cv_sys_max_cmd_len=32750; -fi -AC_PROG_LIBTOOL - -# Checks for header files. -AC_HEADER_STDC -AC_CHECK_HEADERS([getopt.h stdarg.h stdbool.h openssl/ssl.h netinet/in.h time.h sys/param.h sys/socket.h],,, [AC_INCLUDES_DEFAULT]) - -# check for types -AC_CHECK_TYPE(int8_t, char) -AC_CHECK_TYPE(int16_t, short) -AC_CHECK_TYPE(int32_t, int) -AC_CHECK_TYPE(int64_t, long long) -AC_CHECK_TYPE(uint8_t, unsigned char) -AC_CHECK_TYPE(uint16_t, unsigned short) -AC_CHECK_TYPE(uint32_t, unsigned int) -AC_CHECK_TYPE(uint64_t, unsigned long long) -AC_TYPE_SIZE_T -AC_CHECK_TYPE(ssize_t, int) -AC_TYPE_UID_T -AC_TYPE_PID_T -AC_TYPE_OFF_T - -AC_CHECK_TYPE(socklen_t, , - [AC_DEFINE([socklen_t], [int], [Define to 'int' if not defined])], [ -AC_INCLUDES_DEFAULT -#if HAVE_SYS_SOCKET_H -# include -#endif -]) -AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [ -#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_NETINET_IN_H -# include -#endif]) -AC_CHECK_TYPE(in_port_t, [], [AC_DEFINE([in_port_t], [uint16_t], [in_port_t])], [ -#if HAVE_SYS_TYPES_H -# include -#endif -#if HAVE_NETINET_IN_H -# include -#endif]) - # check to see if libraries are needed for these functions. AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(nsl, inet_pton) @@ -279,7 +284,9 @@ AH_BOTTOM([ #else /* !HAVE_ATTR_FORMAT */ # define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */ #endif /* !HAVE_ATTR_FORMAT */ -#if defined(__cplusplus) +#if defined(DOXYGEN) +# define ATTR_UNUSED(x) x +#elif defined(__cplusplus) # define ATTR_UNUSED(x) #elif defined(HAVE_ATTR_UNUSED) # define ATTR_UNUSED(x) x __attribute__((unused)) diff --git a/doc/Changelog b/doc/Changelog index e49b2e798..93c6aef61 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,10 @@ - added libevent to configure to link with. - util/netevent setup work. - configure searches for libevent. + - search for libs at end of configure (when other headers and types + have been found). + - doxygen works with ATTR_UNUSED(). + - util/netevent implementation. 22 January 2007: Wouter - Designed header file for network communication. diff --git a/doc/unbound.doxygen b/doc/unbound.doxygen index 2a766f0d9..6b71902bc 100644 --- a/doc/unbound.doxygen +++ b/doc/unbound.doxygen @@ -971,13 +971,13 @@ ENABLE_PREPROCESSING = YES # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. -MACRO_EXPANSION = NO +MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. -EXPAND_ONLY_PREDEF = NO +EXPAND_ONLY_PREDEF = YES # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. @@ -1005,14 +1005,14 @@ INCLUDE_FILE_PATTERNS = *.h # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = DOXYGEN # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. -EXPAND_AS_DEFINED = +EXPAND_AS_DEFINED = ATTR_UNUSED # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all function-like macros that are alone diff --git a/util/netevent.c b/util/netevent.c index c26552644..76553bed2 100644 --- a/util/netevent.c +++ b/util/netevent.c @@ -17,6 +17,8 @@ #include "util/log.h" #include +/* -------- Start of local definitions -------- */ + /* we use libevent */ #include @@ -37,7 +39,42 @@ struct internal_base { struct event_base* base; }; -struct comm_base* comm_base_create() +/** + * handle libevent callback for udp comm point. + * @param fd: file descriptor. + * @param event: event bits from libevent: + * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. + * @param arg: the comm_point structure. + */ +static void comm_point_udp_callback(int fd, short event, void* arg); + +/** + * handle libevent callback for tcp accept comm point + * @param fd: file descriptor. + * @param event: event bits from libevent: + * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. + * @param arg: the comm_point structure. + */ +static void comm_point_tcp_accept_callback(int fd, short event, void* arg); + +/** + * handle libevent callback for tcp data comm point + * @param fd: file descriptor. + * @param event: event bits from libevent: + * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. + * @param arg: the comm_point structure. + */ +static void comm_point_tcp_handle_callback(int fd, short event, void* arg); + +/** create a tcp handler with a parent */ +static struct comm_point* comm_point_create_tcp_handler( + struct comm_base *base, struct comm_point* parent, size_t bufsize, + comm_point_callback_t* callback, void* callback_arg); + +/* -------- End of local definitions -------- */ + +struct comm_base* +comm_base_create() { struct comm_base* b = (struct comm_base*)calloc(1, sizeof(struct comm_base)); @@ -57,7 +94,8 @@ struct comm_base* comm_base_create() return b; } -void comm_base_delete(struct comm_base* b) +void +comm_base_delete(struct comm_base* b) { /* No way to delete event_base! leaks. */ b->eb->base = NULL; @@ -65,7 +103,8 @@ void comm_base_delete(struct comm_base* b) free(b); } -void comm_base_dispatch(struct comm_base* b) +void +comm_base_dispatch(struct comm_base* b) { int retval; while(1) { @@ -77,13 +116,6 @@ void comm_base_dispatch(struct comm_base* b) } } -/** - * libevent callback routine for commpoint udp - * @param fd: file descriptor. - * @param event: event bits from libevent: - * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. - * @param arg: the comm_point structure. - */ static void comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void* arg) @@ -92,13 +124,6 @@ comm_point_udp_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event), log_info("callback udp for %x", (int)c); } -/** - * libevent callback routine for commpoint tcp accept listeners. - * @param fd: file descriptor. - * @param event: event bits from libevent: - * EV_READ, EV_WRITE, EV_SIGNAL, EV_TIMEOUT. - * @param arg: the comm_point structure. - */ static void comm_point_tcp_accept_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event), void* arg) @@ -107,8 +132,16 @@ comm_point_tcp_accept_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event), log_info("callback tcpaccept for %x", (int)c); } -struct comm_point* comm_point_create_udp(struct comm_base *base, - int fd, struct buffer* buffer, +static void +comm_point_tcp_handle_callback(int ATTR_UNUSED(fd), short ATTR_UNUSED(event), + void* arg) +{ + struct comm_point* c = (struct comm_point*)arg; + log_info("callback tcpaccept for %x", (int)c); +} + +struct comm_point* +comm_point_create_udp(struct comm_base *base, int fd, struct buffer* buffer, comm_point_callback_t* callback, void* callback_arg) { struct comm_point* c = (struct comm_point*)calloc(1, @@ -149,12 +182,52 @@ struct comm_point* comm_point_create_udp(struct comm_base *base, return c; } -struct comm_point* +static struct comm_point* comm_point_create_tcp_handler(struct comm_base *base, struct comm_point* parent, size_t bufsize, comm_point_callback_t* callback, void* callback_arg) { - return NULL; + struct comm_point* c = (struct comm_point*)calloc(1, + sizeof(struct comm_point)); + short evbits; + if(!c) + return NULL; + c->ev = (struct internal_event*)calloc(1, + sizeof(struct internal_event)); + if(!c->ev) { + free(c); + return NULL; + } + c->fd = -1; + c->buffer = NULL /* routine to create new buffer! bufsize */; + c->timeout = NULL; + c->tcp_is_reading = 0; + c->tcp_byte_count = 0; + c->tcp_parent = parent; + c->cur_tcp_count = 0; + c->max_tcp_count = 0; + c->tcp_handlers = NULL; + c->tcp_free = NULL; + c->type = comm_tcp; + c->tcp_do_close = 0; + c->tcp_do_toggle_rw = 0; + c->callback = callback; + c->cb_arg = callback_arg; + /* add to parent free list */ + c->tcp_free = parent->tcp_free; + parent->tcp_free = c; + /* libevent stuff */ + evbits = EV_PERSIST | EV_READ; + event_set(&c->ev->ev, c->fd, evbits, comm_point_tcp_handle_callback, c); + if(event_base_set(base->eb->base, &c->ev->ev) != 0) + { + log_err("could not basetset tcphdl event"); + parent->tcp_free = c->tcp_free; + free(c->ev); + free(c); + return NULL; + } + return c; } struct comm_point* @@ -210,12 +283,17 @@ comm_point_create_tcp(struct comm_base *base, int fd, int num, size_t bufsize, for(i=0; itcp_handlers[i] = comm_point_create_tcp_handler(base, c, bufsize, callback, callback_arg); + if(!c->tcp_handlers[i]) { + comm_point_delete(c); + return NULL; + } } return c; } -void comm_point_close(struct comm_point* c) +void +comm_point_close(struct comm_point* c) { if(c->fd != -1) close(c->fd); @@ -225,8 +303,11 @@ void comm_point_close(struct comm_point* c) } } -void comm_point_delete(struct comm_point* c) +void +comm_point_delete(struct comm_point* c) { + if(!c) + return; comm_point_close(c); if(c->tcp_handlers) { int i;