From Magne.Mahre at Sun.COM Thu Sep 6 14:15:40 2007 From: Magne.Mahre at Sun.COM (=?ISO-8859-1?Q?Magne_M=E6hre?=) Date: Thu Sep 6 14:16:06 2007 Subject: [Libevent-users] [PATCH] Compiling on Solaris/OpenSolaris with Sun Studio 12 Message-ID: <46E043CC.40706@sun.com> I tried to build 1.3d and svn trunk today, and came across a couple of issues. A patch is attached that remedies these problems, and I _think_ they won't break anything. 1. configure.in a) Added AC_CHECK_LIB for inet_ntoa in libnsl (it's where it lives on Solaris) b) Changed the checks for __func__ and __FUNCTION__ so it no longer tries to declare an inner function (the void foo() {}). Inner functions are not allowed in ISO C, so even though gcc accepts it, other compilers (like Sun Studio) don't. 2. test/regress.c a) Changed references for u_int32_t to uint32_t, since the latter is C99, and is also what's tested for in the configure script. --Magne -------------- next part -------------- A non-text attachment was scrubbed... Name: libevent-solaris.diff Type: text/x-patch Size: 1583 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070906/c0ef2304/libevent-solaris.bin From nickm at freehaven.net Thu Sep 6 20:11:39 2007 From: nickm at freehaven.net (Nick Mathewson) Date: Thu Sep 6 20:11:44 2007 Subject: [Libevent-users] [PATCH] Compiling on Solaris/OpenSolaris with Sun Studio 12 In-Reply-To: <46E043CC.40706@sun.com> References: <46E043CC.40706@sun.com> Message-ID: <20070907001139.GA22815@totoro.wangafu.net> On Thu, Sep 06, 2007 at 08:15:40PM +0200, Magne M?hre wrote: > > I tried to build 1.3d and svn trunk today, and came across a couple of > issues. > A patch is attached that remedies these problems, and I _think_ they won't > break > anything. > > 1. configure.in > a) Added AC_CHECK_LIB for inet_ntoa in libnsl (it's where it lives on > Solaris) > > b) Changed the checks for __func__ and __FUNCTION__ so it no longer tries > to > declare an inner function (the void foo() {}). Inner functions are not > allowed in ISO C, so even though gcc accepts it, other compilers > (like Sun Studio) don't. > > 2. test/regress.c > > a) Changed references for u_int32_t to uint32_t, since the latter is C99, > and is also what's tested for in the configure script. Thanks for your patches; I've checked them in to the subversion repository. They should appear in the next release. -- Nick Mathewson -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 652 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070906/e03db3bc/attachment.bin From nickm at freehaven.net Thu Sep 6 21:23:27 2007 From: nickm at freehaven.net (Nick Mathewson) Date: Thu Sep 6 21:23:45 2007 Subject: [Libevent-users] Re: No Date header in HTTP/1.1 response In-Reply-To: References: <033F81DE-9BF0-4523-8C5F-88827430F891@distal.com> <46CC89F3.6080809@gratuitous.net> <46CD5334.8090307@kneschke.de> Message-ID: <20070907012327.GB22815@totoro.wangafu.net> On Thu, Aug 23, 2007 at 12:14:09PM +0200, Ralph Moritz wrote: > On 23/08/07, Jan Kneschke wrote: > > This patch will break on non C99 compilers with mixed declaration/code > > errors. Please move the declarations up to the start of this block. > > Thanks for spotting that. New patch below. Hopefully this one's > kosher. Thanks! I've checked in to trunk and to the 1.3 branch, with the following changes: - Now, it only adds the Date header if there is not a Date header already. - On Windows, it uses gmtime() instead of gmtime_r(). (Windows has no gmtime_r(), but that's okay since its gmtime() uses thread-local storage to achieve thread-safety. Hooray for cross-platform programming, such as it is.) Please try it out and let us know if there are any problems? yrs, -- Nick Mathewson -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 652 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070906/31d7bfa2/attachment.bin From ralmoritz at gmail.com Fri Sep 7 03:52:05 2007 From: ralmoritz at gmail.com (Ralph Moritz) Date: Fri Sep 7 03:52:17 2007 Subject: [Libevent-users] Re: No Date header in HTTP/1.1 response In-Reply-To: <20070907012327.GB22815@totoro.wangafu.net> References: <033F81DE-9BF0-4523-8C5F-88827430F891@distal.com> <46CC89F3.6080809@gratuitous.net> <46CD5334.8090307@kneschke.de> <20070907012327.GB22815@totoro.wangafu.net> Message-ID: On 07/09/07, Nick Mathewson wrote: > On Thu, Aug 23, 2007 at 12:14:09PM +0200, Ralph Moritz wrote: > > On 23/08/07, Jan Kneschke wrote: > > > This patch will break on non C99 compilers with mixed declaration/code > > > errors. Please move the declarations up to the start of this block. > > > > Thanks for spotting that. New patch below. Hopefully this one's > > kosher. > > Thanks! I've checked in to trunk and to the 1.3 branch, with the > following changes: > - Now, it only adds the Date header if there is not a Date header > already. > > - On Windows, it uses gmtime() instead of gmtime_r(). (Windows has > no gmtime_r(), but that's okay since its gmtime() uses > thread-local storage to achieve thread-safety. Hooray for > cross-platform programming, such as it is.) > > Please try it out and let us know if there are any problems? Cool. I'll try it out tomorrow. -- Ralph Moritz Ph: +27 84 626 9070 GPG Public Key: http://ralphm.info/public.gpg From pomarancde23 at post.cz Sat Sep 8 16:15:44 2007 From: pomarancde23 at post.cz (tom) Date: Sat Sep 8 16:15:49 2007 Subject: [Libevent-users] read stdin pipe Message-ID: <871.1389-21302-1022438403-1189282544@post.cz> Hi, I'm writing a daemon using libevent. The daemon is started like this: "program_A | daemon" It gets a pipe on standard input. The program_A is writing to this pipe and the daemon must process the input gathered from the pipe. I must be doing something wrong as my callback function set in event_set is called nonstop. A trace had shown that epoll_wait() in epoll_dispatch() is not waiting at all and afterwards the read() in the callback returns always 0. When I start the daemon like this "./daemon" and write on the console, it all works fine as it should. Here is my daemon skeleton: struct event ev; void read_stdin (int fd, short flags, void *data) { .. ret = read(fd, buf, BUFSIZE); .. } main () { base = event_init(); event_set(&ev, 0, EV_READ | EV_PERSIST, read_stdin, NULL); event_add(&ev, NULL); event_base_loop(base, 0); } Thanks for any advice in advanced, Tom From provos at citi.umich.edu Sat Sep 8 16:49:22 2007 From: provos at citi.umich.edu (Niels Provos) Date: Sat Sep 8 16:49:27 2007 Subject: [Libevent-users] read stdin pipe In-Reply-To: <871.1389-21302-1022438403-1189282544@post.cz> References: <871.1389-21302-1022438403-1189282544@post.cz> Message-ID: <850f7cbe0709081349l3e7f36b2o7e0511703a1ee4a@mail.gmail.com> When the read returns 0, it means that you have EOF on the file descriptor. You need to delete the read event at that point. It's not entirely surprising that stdin goes away when you daemonize a program. Niels. On 9/8/07, tom wrote: > Hi, > > I'm writing a daemon using libevent. The daemon is started like this: > "program_A | daemon" > It gets a pipe on standard input. The program_A is writing to this pipe and the daemon must process the input gathered from the pipe. I must be doing something wrong as my callback function set in event_set is called nonstop. A trace had shown that epoll_wait() in epoll_dispatch() is not waiting at all and afterwards the read() in the callback returns always 0. When I start the daemon like this "./daemon" and write on the console, it all works fine as it should. > > Here is my daemon skeleton: > > struct event ev; > > void read_stdin (int fd, short flags, void *data) > { > .. > ret = read(fd, buf, BUFSIZE); > .. > } > > main () > { > base = event_init(); > event_set(&ev, 0, EV_READ | EV_PERSIST, read_stdin, NULL); > event_add(&ev, NULL); > event_base_loop(base, 0); > } > > > Thanks for any advice in advanced, > Tom > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkey.org/mailman/listinfo/libevent-users > > From charles at rebelbase.com Mon Sep 10 15:46:37 2007 From: charles at rebelbase.com (Charles Kerr) Date: Mon Sep 10 15:49:11 2007 Subject: [Libevent-users] patch to get event_debug working again in svn trunk Message-ID: <46E59F1D.2070907@rebelbase.com> The current svn trunk (r428) doesn't build when debugging messages are turned on. This small patch makes the changes need to get things compiling again. Index: http.c =================================================================== --- http.c (revision 428) +++ http.c (working copy) @@ -1499,7 +1499,7 @@ evcon->fd = bind_socket(evcon->bind_address, 0); if (evcon->fd == -1) { event_debug(("%s: failed to bind to \"%s\"", - __func__, bind_address)); + __func__, evcon->bind_address)); return (-1); } @@ -2439,7 +2439,7 @@ if (ai == NULL) { event_debug(("%s: make_addrinfo: \"%s:%d\"", - __func__, evcon->address, evcon->port)); + __func__, address, port)); return (-1); } From mark at heily.com Wed Sep 5 19:48:19 2007 From: mark at heily.com (Mark Heily) Date: Wed Sep 12 00:35:06 2007 Subject: [Libevent-users] [patch] inline Doxygen documentation Message-ID: <1189036099.9215.3.camel@voltaire> Niels, Here is the patch that adds inline Doxygen documentation comments to the public libevent header files. After applying the patch, you can execute the 'doxygen' command to generated the API reference manual in HTML format. It also produces manpages and Latex format (which can be used to generate PDF). This patch applies cleanly to the trunk as of 9/5/2007. Enjoy, Mark Index: Doxyfile =================================================================== --- Doxyfile (revision 0) +++ Doxyfile (revision 0) @@ -0,0 +1,230 @@ +# Doxyfile 1.5.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = libevent + +# Place all output under 'doxygen/' + +OUTPUT_DIRECTORY = doxygen/ + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = event.h evdns.h evhttp.h + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \ \batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = YES + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# 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 + +# 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. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = TAILQ_ENTRY RB_ENTRY _EVENT_DEFINED_TQENTRY + +# 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 = + +# 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 +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES Index: evhttp.h =================================================================== --- evhttp.h (revision 406) +++ evhttp.h (working copy) @@ -40,7 +40,8 @@ #undef WIN32_LEAN_AND_MEAN #endif -/* +/** @file evhttp.h + * * Basic support for HTTP serving. * * As libevent is a library for dealing with event notification and most @@ -64,40 +65,74 @@ struct evhttp_request; struct evkeyvalq; -/* - * creates a new HTTP server; if base is specified events from the http server - * are going to be created on that event base. +/** Create a new HTTP server + * + * @param base (optional) the event base to receive the HTTP events + * @return a pointer to a newly initialized evhttp server structure */ struct evhttp *evhttp_new(struct event_base *base); -/* - * binds the http server to specific port and can be called multiple times - * to bind the same http server to multiple different ports. +/** + * Start an HTTP server on the specified address and port. + * + * Can be called multiple times to bind the same http server + * to multiple different ports. + * + * @param address a string containing the IP address to listen(2) on + * @param port the port number to listen on + * @return a newly allocated evhttp struct + * @see evhttp_free() */ int evhttp_bind_socket(struct evhttp *http, const char *address, u_short port); -/* - * Free the previously created HTTP server. Works only if no requests are - * currently being served. +/** + * Free the previously created HTTP server. + * + * Works only if no requests are currently being served. + * + * @param http the evhttp server object to be freed + * @see evhttp_start() */ void evhttp_free(struct evhttp* http); -/* Set a callback for a specified URI */ +/** Set a callback for a specified URI */ void evhttp_set_cb(struct evhttp *, const char *, void (*)(struct evhttp_request *, void *), void *); -/* Removes the callback for a specified URI */ +/** Removes the callback for a specified URI */ int evhttp_del_cb(struct evhttp *, const char *); -/* Set a callback for all requests that are not caught by specific callbacks */ +/** Set a callback for all requests that are not caught by specific callbacks */ void evhttp_set_gencb(struct evhttp *, void (*)(struct evhttp_request *, void *), void *); +/** + * Set the timeout for an HTTP request. + * + * @param http an evhttp object + * @param timeout_in_secs the timeout, in seconds + */ void evhttp_set_timeout(struct evhttp *, int timeout_in_secs); /* Request/Response functionality */ +/** + * Send an HTML error message to the client. + * + * @param req a request object + * @param error the HTTP error code + * @param reason a brief explanation of the error + */ void evhttp_send_error(struct evhttp_request *, int, const char *); + +/** + * Send an HTML reply to the client. + * + * @param req a request object + * @param code the HTTP response code to send + * @param reason a brief message to send with the response code + * @param databuf the body of the response + */ void evhttp_send_reply(struct evhttp_request *, int, const char *, struct evbuffer *); @@ -119,7 +154,7 @@ enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE }; -/* +/** * the request structure that a server receives. * WARNING: expect this structure to change. I will try to provide * reasonable accessors. @@ -170,7 +205,7 @@ void (*chunk_cb)(struct evhttp_request *, void *); }; -/* +/** * Creates a new request object that needs to be filled in with the request * parameters. The callback is executed when the request completed or an * error occurred. @@ -178,14 +213,14 @@ struct evhttp_request *evhttp_request_new( void (*cb)(struct evhttp_request *, void *), void *arg); -/* enable delivery of chunks to requestor */ +/** enable delivery of chunks to requestor */ void evhttp_request_set_chunked_cb(struct evhttp_request *, void (*cb)(struct evhttp_request *, void *)); -/* Frees the request object and removes associated events. */ +/** Frees the request object and removes associated events. */ void evhttp_request_free(struct evhttp_request *req); -/* +/** * A connection object that can be used to for making HTTP requests. The * connection object tries to establish the connection when it is given an * http request object. @@ -193,33 +228,34 @@ struct evhttp_connection *evhttp_connection_new( const char *address, unsigned short port); -/* Frees an http connection */ +/** Frees an http connection */ void evhttp_connection_free(struct evhttp_connection *evcon); -/* Sets the timeout for events related to this connection */ +/** Sets the timeout for events related to this connection */ void evhttp_connection_set_timeout(struct evhttp_connection *evcon, int timeout_in_secs); -/* Sets the retry limit for this connection - -1 repeats indefnitely */ +/** Sets the retry limit for this connection - -1 repeats indefnitely */ void evhttp_connection_set_retries(struct evhttp_connection *evcon, int retry_max); -/* Set a callback for connection close. */ +/** Set a callback for connection close. */ void evhttp_connection_set_closecb(struct evhttp_connection *evcon, void (*)(struct evhttp_connection *, void *), void *); -/* - * Associates an event base with the connection - can only be called - * on a freshly created connection object that has not been used yet. +/** Associate an event base with the connection + * + * Can only be called on a freshly created connection object that has not + * been used yet. */ void evhttp_connection_set_base(struct evhttp_connection *evcon, struct event_base *base); -/* Get the remote address and port associated with this connection. */ +/** Get the remote address and port associated with this connection. */ void evhttp_connection_get_peer(struct evhttp_connection *evcon, char **address, u_short *port); -/* The connection gets ownership of the request */ +/** The connection gets ownership of the request */ int evhttp_make_request(struct evhttp_connection *evcon, struct evhttp_request *req, enum evhttp_cmd_type type, const char *uri); @@ -234,10 +270,51 @@ void evhttp_clear_headers(struct evkeyvalq *); /* Miscellaneous utility functions */ + + +/** + Helper function to encode a URI. + + The returned string must be freed by the caller. + + @param uri an unencoded URI + @return a newly allocated URI-encoded string + */ char *evhttp_encode_uri(const char *uri); + + +/** + Helper function to decode a URI. + + The returned string must be freed by the caller. + + @param uri an encoded URI + @return a newly allocated unencoded URI + */ char *evhttp_decode_uri(const char *uri); + + +/** + * Helper function to parse out arguments in a query. + * The arguments are separated by key and value. + * URI should already be decoded. + */ void evhttp_parse_query(const char *uri, struct evkeyvalq *); + + +/** + * Escape HTML character entities in a string. + * + * Replaces <, >, ", ' and & with <, >, ", + * ' and & correspondingly. + * + * The returned string needs to be freed by the caller. + * + * @param html an unescaped HTML string + * @return an escaped HTML string + */ char *evhttp_htmlescape(const char *html); + #ifdef __cplusplus } #endif Index: evdns.h =================================================================== --- evdns.h (revision 406) +++ evdns.h (working copy) @@ -47,7 +47,8 @@ * the source verbatim in their source distributions) */ -/* +/** @file evdns.h + * * Welcome, gentle reader * * Async DNS lookups are really a whole lot harder than they should be, @@ -136,85 +137,6 @@ * Query: www.abc * Order: www.abc., www.abc.myhome.net * - * API reference: - * - * int evdns_nameserver_add(unsigned long int address) - * Add a nameserver. The address should be an IP address in - * network byte order. The type of address is chosen so that - * it matches in_addr.s_addr. - * Returns non-zero on error. - * - * int evdns_nameserver_ip_add(const char *ip_as_string) - * This wraps the above function by parsing a string as an IP - * address and adds it as a nameserver. - * Returns non-zero on error - * - * int evdns_resolve(const char *name, int flags, - * evdns_callback_type callback, - * void *ptr) - * Resolve a name. The name parameter should be a DNS name. - * The flags parameter should be 0, or DNS_QUERY_NO_SEARCH - * which disables searching for this query. (see defn of - * searching above). - * - * The callback argument is a function which is called when - * this query completes and ptr is an argument which is passed - * to that callback function. - * - * Returns non-zero on error - * - * void evdns_search_clear() - * Clears the list of search domains - * - * void evdns_search_add(const char *domain) - * Add a domain to the list of search domains - * - * void evdns_search_ndots_set(int ndots) - * Set the number of dots which, when found in a name, causes - * the first query to be without any search domain. - * - * int evdns_count_nameservers(void) - * Return the number of configured nameservers (not necessarily the - * number of running nameservers). This is useful for double-checking - * whether our calls to the various nameserver configuration functions - * have been successful. - * - * int evdns_clear_nameservers_and_suspend(void) - * Remove all currently configured nameservers, and suspend all pending - * resolves. Resolves will not necessarily be re-attempted until - * evdns_resume() is called. - * - * int evdns_resume(void) - * Re-attempt resolves left in limbo after an earlier call to - * evdns_clear_nameservers_and_suspend(). - * - * int evdns_config_windows_nameservers(void) - * Attempt to configure a set of nameservers based on platform settings on - * a win32 host. Preferentially tries to use GetNetworkParams; if that fails, - * looks in the registry. Returns 0 on success, nonzero on failure. - * - * int evdns_resolv_conf_parse(int flags, const char *filename) - * Parse a resolv.conf like file from the given filename. - * - * See the man page for resolv.conf for the format of this file. - * The flags argument determines what information is parsed from - * this file: - * DNS_OPTION_SEARCH - domain, search and ndots options - * DNS_OPTION_NAMESERVERS - nameserver lines - * DNS_OPTION_MISC - timeout and attempts options - * DNS_OPTIONS_ALL - all of the above - * The following directives are not parsed from the file: - * sortlist, rotate, no-check-names, inet6, debug - * - * Returns non-zero on error: - * 0 no errors - * 1 failed to open file - * 2 failed to stat file - * 3 file too large - * 4 out of memory - * 5 short read from file - * 6 no nameservers in file - * * Internals: * * Requests are kept in two queues. The first is the inflight queue. In @@ -242,27 +164,27 @@ extern "C" { #endif -/* Error codes 0-5 are as described in RFC 1035. */ +/** Error codes 0-5 are as described in RFC 1035. */ #define DNS_ERR_NONE 0 -/* The name server was unable to interpret the query */ +/** The name server was unable to interpret the query */ #define DNS_ERR_FORMAT 1 -/* The name server was unable to process this query due to a problem with the +/** The name server was unable to process this query due to a problem with the * name server */ #define DNS_ERR_SERVERFAILED 2 -/* The domain name does not exist */ +/** The domain name does not exist */ #define DNS_ERR_NOTEXIST 3 -/* The name server does not support the requested kind of query */ +/** The name server does not support the requested kind of query */ #define DNS_ERR_NOTIMPL 4 -/* The name server refuses to reform the specified operation for policy +/** The name server refuses to reform the specified operation for policy * reasons */ #define DNS_ERR_REFUSED 5 -/* The reply was truncated or ill-formated */ +/** The reply was truncated or ill-formated */ #define DNS_ERR_TRUNCATED 65 -/* An unknown error occurred */ +/** An unknown error occurred */ #define DNS_ERR_UNKNOWN 66 -/* Communication with the server timed out */ +/** Communication with the server timed out */ #define DNS_ERR_TIMEOUT 67 -/* The request was canceled because the DNS subsystem was shut down. */ +/** The request was canceled because the DNS subsystem was shut down. */ #define DNS_ERR_SHUTDOWN 68 #define DNS_IPv4_A 1 @@ -276,7 +198,7 @@ #define DNS_OPTION_MISC 4 #define DNS_OPTIONS_ALL 7 -/* +/** * The callback that contains the results from a lookup. * - type is either DNS_IPv4_A or DNS_PTR or DNS_IPv6_AAAA * - count contains the number of addresses of form type @@ -285,30 +207,244 @@ */ typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); +/** + Initialize the asynchronous DNS library. + + This function initializes support for non-blocking name resolution by calling + evdns_resolv_conf_parse() on UNIX and evdns_config_windows_nameservers() on Windows. + + @return 0 if successful, or -1 if an error occurred + @see evdns_shutdown() + */ int evdns_init(void); + + +/** + Shut down the asynchronous DNS resolver and terminate all active requests. + + If the 'fail_requests' option is enabled, all active requests will return + an empty result with the error flag set to DNS_ERR_SHUTDOWN. Otherwise, + the requests will be silently discarded. + + @param fail_requests if zero, active requests will be aborted; if non-zero, + active requests will return DNS_ERR_SHUTDOWN. + @see evdns_init() + */ void evdns_shutdown(int fail_requests); + + +/** + Convert a DNS error code to a string. + + @param err the DNS error code + @return a string containing an explanation of the error code +*/ const char *evdns_err_to_string(int err); + + +/** + Add a nameserver. + + The address should be an IP address in network byte order. + The type of address is chosen so that it matches in_addr.s_addr. + + @param address an IP address in network byte order + @return 0 if successful, or -1 if an error occurred + @see evdns_nameserver_ip_add() + */ int evdns_nameserver_add(unsigned long int address); + + +/** + Get the number of configured nameservers. + + This returns the number of configured nameservers (not necessarily the + number of running nameservers). This is useful for double-checking + whether our calls to the various nameserver configuration functions + have been successful. + + @return the number of configured nameservers + @see evdns_nameserver_add() + */ int evdns_count_nameservers(void); + + +/** + Remove all configured nameservers, and suspend all pending resolves. + + Resolves will not necessarily be re-attempted until evdns_resume() is called. + + @return 0 if successful, or -1 if an error occurred + @see evdns_resume() + */ int evdns_clear_nameservers_and_suspend(void); + + +/** + Resume normal operation and continue any suspended resolve requests. + + Re-attempt resolves left in limbo after an earlier call to + evdns_clear_nameservers_and_suspend(). + + @return 0 if successful, or -1 if an error occurred + @see evdns_clear_nameservers_and_suspend() + */ int evdns_resume(void); + + +/** + Add a nameserver. + + This wraps the evdns_nameserver_add() function by parsing a string as an IP + address and adds it as a nameserver. + + @return 0 if successful, or -1 if an error occurred + @see evdns_nameserver_add() + */ int evdns_nameserver_ip_add(const char *ip_as_string); + + +/** + Lookup an A record for a given name. + + @param name a DNS hostname + @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. + @param callback a callback function to invoke when the request is completed + @param ptr an argument to pass to the callback function + @return 0 if successful, or -1 if an error occurred + @see evdns_resolve_ipv6(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() + */ int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr); + + +/** + Lookup an AAAA record for a given name. + + @param name a DNS hostname + @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. + @param callback a callback function to invoke when the request is completed + @param ptr an argument to pass to the callback function + @return 0 if successful, or -1 if an error occurred + @see evdns_resolve_ipv4(), evdns_resolve_reverse(), evdns_resolve_reverse_ipv6() + */ int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr); + struct in_addr; struct in6_addr; + +/** + Lookup a PTR record for a given IP address. + + @param in an IPv4 address + @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. + @param callback a callback function to invoke when the request is completed + @param ptr an argument to pass to the callback function + @return 0 if successful, or -1 if an error occurred + @see evdns_resolve_reverse_ipv6() + */ int evdns_resolve_reverse(struct in_addr *in, int flags, evdns_callback_type callback, void *ptr); + + +/** + Lookup a PTR record for a given IPv6 address. + + @param in an IPv6 address + @param flags either 0, or DNS_QUERY_NO_SEARCH to disable searching for this query. + @param callback a callback function to invoke when the request is completed + @param ptr an argument to pass to the callback function + @return 0 if successful, or -1 if an error occurred + @see evdns_resolve_reverse_ipv6() + */ int evdns_resolve_reverse_ipv6(struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr); + + +/** + Set the value of a configuration option. + + The currently available configuration options are: + + ndots, timeout, max-timeouts, max-inflight, and attempts + + @param option the name of the configuration option to be modified + @param val the value to be set + @param flags either 0 | DNS_OPTION_SEARCH | DNS_OPTION_MISC + @return 0 if successful, or -1 if an error occurred + */ int evdns_set_option(const char *option, const char *val, int flags); -int evdns_resolv_conf_parse(int flags, const char *); + + +/** + Parse a resolv.conf file. + + The 'flags' parameter determines what information is parsed from + the resolv.conf file. See the man page for resolv.conf for the format of this file. + The following directives are not parsed from the file: sortlist, rotate, no-check-names, inet6, debug + + If this function encounters an error, the possible return values are: + 1 = failed to open file, 2 = failed to stat file, 3 = file too large, + 4 = out of memory, 5 = short read from file, 6 = no nameservers listed in the file + + @param flags any of DNS_OPTION_NAMESERVERS|DNS_OPTION_SEARCH| DNS_OPTION_MISC|DNS_OPTIONS_ALL + @param filename the path to the resolv.conf file + @return 0 if successful, or various positive error codes if an error occurred (see above) + @see resolv.conf(3), evdns_config_windows_nameservers() + */ +int evdns_resolv_conf_parse(int flags, const char *filename); + + +/** + Obtain nameserver information using the Windows API. + + Attempt to configure a set of nameservers based on platform settings on + a win32 host. Preferentially tries to use GetNetworkParams; if that fails, + looks in the registry. + + @return 0 if successful, or -1 if an error occurred + @see evdns_resolv_conf_parse() + */ #ifdef MS_WINDOWS int evdns_config_windows_nameservers(void); #endif + + +/** + Clear the list of search domains. + */ void evdns_search_clear(void); + + +/** + Add a domain to the list of search domains + + @param domain the domain to be added to the search list + */ void evdns_search_add(const char *domain); + + +/** + Set the 'ndots' parameter for searches. + + Sets the number of dots which, when found in a name, causes + the first query to be without any search domain. + + @param ndots the new ndots parameter + */ void evdns_search_ndots_set(const int ndots); +/** + A callback that is invoked when a log message is generated + + @param is_warning indicates if the log message is a 'warning' + @param msg the content of the log message + */ typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg); + + +/** + Set the callback function to handle log messages. + + @param fn the callback to be invoked when a log message is generated + */ void evdns_set_log_fn(evdns_debug_log_fn_type fn); #define DNS_NO_SEARCH 1 Index: event.h =================================================================== --- event.h (revision 406) +++ event.h (working copy) @@ -27,6 +27,95 @@ #ifndef _EVENT_H_ #define _EVENT_H_ +/** @mainpage + + @section intro Introduction + + libevent is an event notification library for developing scalable + network servers. The libevent API provides a mechanism to execute a callback function when a specific + event occurs on a file descriptor or after a timeout has been reached. Furthermore, + libevent also support callbacks due to signals or regular timeouts. + + libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop. + + Currently, libevent supports /dev/poll, kqueue(2), select(2), poll(2) and epoll(4). It also has experimental support for real-time signals. The internal event mechanism is completely independent of the exposed event API, and a simple update of libevent can provide new functionality without having to redesign the applications. As a result, Libevent allows for portable application development and provides the most scalable event notification mechanism available on an operating system. Libevent can also be used for multi-threaded aplications; see Steven Grimm's explanation. Libevent should compile on Linux, *BSD, Mac OS X, Solaris and Windows. + + @section usage Standard usage + + Every program that uses libevent must include the header, and pass the -levent flag to the linker. + Before using any of the functions in the library, you must call event_init() to perform + one-time initialization of the libevent library. + + @section event Event notification + + For each file descriptor that you wish to monitor, you must declare an event structure and call event_set() to initialize the members of the structure. + To enable notification, you add the structure + to the list of monitored events by calling event_add(). The + event structure must remain allocated as long as it is active, so it should be + allocated on the heap. Finally, you call event_dispatch() + to loop and dispatch events. + + @section bufferevent I/O Buffers + + libevent provides an abstraction on top of the regular event callbacks. This abstraction is called a buffered event. A buffered event provides input and output buffers that get filled and drained automatically. The user of a buffered event no longer deals directly with the I/O, but instead is reading from input and writing to output buffers. + +Once initialized via bufferevent_new(), the bufferevent structure can be used repeatedly with bufferevent_enable() and bufferevent_disable(). Instead of reading and writing directly to a socket, you would call bufferevent_read() and bufferevent_write(). + +When read enabled the bufferevent will try to read from the file descriptor and call the read callback. The write callback is executed whenever the output buffer is drained below the write low watermark, which is 0 by default. + + @section timers Timers + + libevent can also be used to create timers that invoke a callback after a + certain amount of time has expired. The evtimer_set() function prepares + an event struct to be used as a timer. To activate the timer, call evtimer_add(). Timers can be deactivated by calling evtimer_del(). + + @section timeouts Timeouts + + In addition to simple timers, libevent can assign timeout events to file + descriptors that are triggered whenever a certain amount of time has passed + with no activity on a file descriptor. The timeout_set() function initializes + an event struct for use as a timeout. Once initialized, the event must be + activated by using timeout_add(). To cancel the timeout, call timeout_del(). + + @section evdns Asynchronous DNS resolution + + libevent provides an asynchronous DNS resolver that should be used instead of the + standard DNS resolver functions. These functions can be imported by including + the header in your program. Before using any of the resolver functions, you must call evdns_init() to initialize the library. To convert a hostname to an IP address, you call + the evdns_resolve_ipv4() function. To perform a reverse lookup, you would call the + evdns_resolve_reverse() function. All of these functions use callbacks to avoid + blocking while the lookup is performed. + + @section evhttp Event-driven HTTP servers + + libevent provides a very simple event-driven HTTP server that can be embedded in your program + and used to service HTTP requests. + + To use this capability, you need to include the header in your program. + You create the server by calling evhttp_start() and providing the address and port to listen on. You then register one or more callbacks to handle incoming requests. Each URI can be assigned a callback via the evhttp_set_cb() function. A generic callback function can also be registered via evhttp_set_gencb(); this callback will be invoked if no other callbacks have been + registered for a given URI. + + @section api API Reference + + To browse the complete documentation of the libevent API, click on any of the following links. + + event.h + The primary libevent header + + evdns.h + Asynchronous DNS resolution + + evhttp.h + An embedded libevent-based HTTP server + + */ + +/** @file event.h + + A library for writing event-driven network servers + + */ + #ifdef __cplusplus extern "C" { #endif @@ -141,11 +230,44 @@ void (*dealloc)(struct event_base *, void *); }; +/** + Initialize the event API. + + The event API needs to be initialized with event_init() before it can be + used. + */ void *event_init(void); + + +/** + Loop to process events. + + In order to process events, an application needs to call + event_dispatch(). This function only returns on error, and should + replace the event core of the application program. + + @see event_base_dispatch() + */ int event_dispatch(void); + + +/** + Threadsafe event dispatching loop. + + @param eb the event_base structure returned by event_init() + @see event_init(), event_dispatch() + */ int event_base_dispatch(struct event_base *); + + +/** + Deallocate all memory associated with an event_base. + + @param eb an event_base to be freed + */ void event_base_free(struct event_base *); + #define _EVENT_LOG_DEBUG 0 #define _EVENT_LOG_MSG 1 #define _EVENT_LOG_WARN 2 @@ -153,25 +275,123 @@ typedef void (*event_log_cb)(int severity, const char *msg); void event_set_log_callback(event_log_cb cb); -/* Associate a different event base with an event */ +/** + Associate a different event base with an event. + + @param eb the event base + @param ev the event + */ int event_base_set(struct event_base *, struct event *); -#define EVLOOP_ONCE 0x01 +/** A flag for event_loop() to indicate ... (FIXME) */ +#define EVLOOP_ONCE 0x01 + +/** A flag for event_loop() to indicate ... (FIXME) */ #define EVLOOP_NONBLOCK 0x02 + +/** + Execute a single event. + + The event_loop() function provides an interface for single pass execution of pending + events. + + @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK + @return 0 if successful, or -1 if an error occurred + @see event_loopexit(), event_base_loop() +*/ int event_loop(int); + +/** + Execute a single event (threadsafe variant). + + The event_base_loop() function provides an interface for single pass execution of pending + events. + + @param eb the event_base structure returned by event_init() + @param flags any combination of EVLOOP_ONCE | EVLOOP_NONBLOCK + @return 0 if successful, or -1 if an error occurred + @see event_loopexit(), event_base_loop() + */ int event_base_loop(struct event_base *, int); -int event_loopexit(struct timeval *); /* Causes the loop to exit */ + +/** + Execute a single event, with a timeout. + + The event_loopexit() function is similar to event_loop(), + but allows the loop to be terminated after some amount of time has passed. + + @param tv the amount of time after which the loop should terminate. + @return 0 if successful, or -1 if an error occurred + @see event_loop(), event_base_loop(), event_base_loopexit() + */ +int event_loopexit(struct timeval *); + + +/** + Execute a single event, with a timeout (threadsafe variant). + + @param eb the event_base structure returned by event_init() + @param tv the amount of time after which the loop should terminate. + @return 0 if successful, or -1 if an error occurred + @see event_loopexit() + */ int event_base_loopexit(struct event_base *, struct timeval *); + +/** + Add a timer event. + + @param ev the event struct + @param tv timeval struct + */ #define evtimer_add(ev, tv) event_add(ev, tv) + + +/** + Define a timer event. + + @param ev event struct to be modified + @param cb callback function + @param arg argument that will be passed to the callback function + */ #define evtimer_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) + + +/** + * Delete a timer event. + * + * @param ev the event struct to be disabled + */ #define evtimer_del(ev) event_del(ev) #define evtimer_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) #define evtimer_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) +/** + * Add a timeout event. + * + * @param ev the event struct to be disabled + * @param tv the timeout value, in seconds + */ #define timeout_add(ev, tv) event_add(ev, tv) + + +/** + * Define a timeout event. + * + * @param ev the event struct to be defined + * @param cb the callback to be invoked when the timeout expires + * @param arg the argument to be passed to the callback + */ #define timeout_set(ev, cb, arg) event_set(ev, -1, 0, cb, arg) + + +/** + * Disable a timeout event. + * + * @param ev the timeout event to be disabled + */ #define timeout_del(ev) event_del(ev) + #define timeout_pending(ev, tv) event_pending(ev, EV_TIMEOUT, tv) #define timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) @@ -182,32 +402,195 @@ #define signal_pending(ev, tv) event_pending(ev, EV_SIGNAL, tv) #define signal_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) +/** + Prepare an event structure to be added. + + The function event_set() prepares the event structure ev to be used in future calls to + event_add() and event_del(). The event will be prepared to call the function specified + by the fn argument with an int argument indicating the file descriptor, a short argument + indicating the type of event, and a void * argument given in the arg argument. The fd + indicates the file descriptor that should be monitored for events. The events can be + either EV_READ, EV_WRITE, or both. Indicating that an application can read or write from + the file descriptor respectively without blocking. + + The function fn will be called with the file descriptor that triggered the event and the + type of event which will be either EV_TIMEOUT, EV_SIGNAL, EV_READ, or EV_WRITE. The + additional flag EV_PERSIST makes an event_add() persistent until event_del() has been + called. + + @param ev an event struct to be modified + @param fd the file descriptor to be monitored + @param event desired events to monitor; can be EV_READ and/or EV_WRITE + @param fn callback function to be invoked when the event occurs + @param arg an argument to be passed to the callback function + + @see event_add(), event_del(), event_once() + + */ void event_set(struct event *, int, short, void (*)(int, short, void *), void *); + +/** + Schedule a one-time event to occur. + + The function event_once() is similar to event_set(). However, it schedules a callback to + be called exactly once and does not require the caller to prepare an event structure. + + @param fd a file descriptor to monitor + @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE + @param callback callback function to be invoked when the event occurs + @param arg an argument to be passed to the callback function + @param timeout the maximum amount of time to wait for the event, or NULL to wait forever + @return 0 if successful, or -1 if an error occurred + @see event_set() + + */ int event_once(int, short, void (*)(int, short, void *), void *, struct timeval *); + + +/** + Schedule a one-time event (threadsafe variant) + + The function event_base_once() is similar to event_set(). However, it schedules a + callback to be called exactly once and does not require the caller to prepare an + event structure. + + @param base an event_base returned by event_init() + @param fd a file descriptor to monitor + @param events event(s) to monitor; can be any of EV_TIMEOUT | EV_READ | EV_WRITE + @param callback callback function to be invoked when the event occurs + @param arg an argument to be passed to the callback function + @param timeout the maximum amount of time to wait for the event, or NULL to wait forever + @return 0 if successful, or -1 if an error occurred + @see event_once() + */ int event_base_once(struct event_base *, int, short, void (*)(int, short, void *), void *, struct timeval *); + +/** + Add an event to the set of monitored events. + + The function event_add() schedules the execution of the ev event when the event specified + in event_set() occurs or in at least the time specified in the tv. If tv is NULL, no + timeout occurs and the function will only be called if a matching event occurs on the + file descriptor. The event in the ev argument must be already initialized by event_set() + and may not be used in calls to event_set() until it has timed out or been removed with + event_del(). If the event in the ev argument already has a scheduled timeout, the old + timeout will be replaced by the new one. + + @param ev an event struct initialized via event_set() + @param timeout the maximum amount of time to wait for the event, or NULL to wait forever + @return 0 if successful, or -1 if an error occurred + @see event_del(), event_set() + */ int event_add(struct event *, struct timeval *); + + +/** + Remove an event from the set of monitored events. + + The function event_del() will cancel the event in the argument ev. If the event has + already executed or has never been added the call will have no effect. + + @param ev an event struct to be removed from the working set + @return 0 if successful, or -1 if an error occurred + @see event_add() + */ int event_del(struct event *); + void event_active(struct event *, int, short); + +/** + + Checks if a specific event is pending or scheduled. + + @param ev an event struct previously passed to event_add() + @param event the requested event type; any of EV_TIMEOUT|EV_READ| EV_WRITE|EV_SIGNAL + @param tv an alternate timeout (FIXME - is this true?) + + @return 1 if the event is pending, or 0 if the event has not occurred + + */ int event_pending(struct event *, short, struct timeval *); + +/** + Test if an event structure has been initialized. + + The event_initialized() macro can be used to check if an event has been initialized. + + @param ev an event structure to be tested + @return 1 if the structure has been initialized, or 0 if it has not been initialized + */ #ifdef WIN32 #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT && (ev)->ev_fd != (int)INVALID_HANDLE_VALUE) #else #define event_initialized(ev) ((ev)->ev_flags & EVLIST_INIT) #endif -/* Some simple debugging functions */ + +/** + Get the libevent version number. + + @return a string containing the version number of libevent + */ const char *event_get_version(void); + + +/** + Get the kernel event notification mechanism used by libevent. + + @return a string identifying the kernel event mechanism (kqueue, epoll, etc.) + */ const char *event_get_method(void); -/* These functions deal with event priorities */ +/** + Set the number of different event priorities. + + By default libevent schedules all active events with the same priority. However, some + time it is desirable to process some events with a higher priority than others. For that + reason, libevent supports strict priority queues. Active events with a lower priority + are always processed before events with a higher priority. + + The number of different priorities can be set initially with the event_priority_init() + function. This function should be called before the first call to event_dispatch(). The + event_priority_set() function can be used to assign a priority to an event. By default, + libevent assigns the middle priority to all events unless their priority is explicitly + set. + + @param npriorities the maximum number of priorities + @return 0 if successful, or -1 if an error occurred + @see event_base_priority_init(), event_priority_set() + + */ int event_priority_init(int); + + +/** + Set the number of different event priorities (threadsafe variant). + + See the description of event_priority_init() for more information. + + @param eb the event_base structure returned by event_init() + @param npriorities the maximum number of priorities + @return 0 if successful, or -1 if an error occurred + @see event_priority_init(), event_priority_set() + */ int event_base_priority_init(struct event_base *, int); + + +/** + Assign a priority to an event. + + @param ev an event struct + @param priority the new priority to be assigned + @return 0 if successful, or -1 if an error occurred + @see event_priority_init() + */ int event_priority_set(struct event *, int); + /* These functions deal with buffering input and output */ struct evbuffer { @@ -259,37 +642,295 @@ short enabled; /* events that are currently enabled */ }; + +/** + Create a new bufferevent. + + libevent provides an abstraction on top of the regular event callbacks. + This abstraction is called a buffered event. A buffered event provides + input and output buffers that get filled and drained automatically. The + user of a buffered event no longer deals directly with the I/O, but + instead is reading from input and writing to output buffers. + + Once initialized, the bufferevent structure can be used repeatedly with + bufferevent_enable() and bufferevent_disable(). + + When read enabled the bufferevent will try to read from the file descriptor and + call the read callback. The write callback is executed whenever the output buffer + is drained below the write low watermark, which is 0 by default. + + If multiple bases are in use, bufferevent_base_set() must be called before enabling the + bufferevent for the first time. + + @param fd the file descriptor from which data is read and written to. + This file descriptor is not allowed to be a pipe(2). + @param readcb callback to invoke when there is data to be read, or NULL if no callback is desired + @param writecb callback to invoke when the file descriptor is ready for writing, or NULL if no callback is desired + @param errorcb callback to invoke when there is an error on the file descriptor + @param cbarg an argument that will be supplied to each of the callbacks (readcb, writecb, and errorcb) + @return a pointer to a newly allocated bufferevent struct, or NULL if an error occurred + @see bufferevent_base_set(), bufferevent_free() + */ struct bufferevent *bufferevent_new(int fd, evbuffercb readcb, evbuffercb writecb, everrorcb errorcb, void *cbarg); + + +/** + Assign a bufferevent to a specific event_base. + + @param base an event_base returned by event_init() + @param bufev a bufferevent struct returned by bufferevent_new() + @return 0 if successful, or -1 if an error occurred + @see bufferevent_new() + */ int bufferevent_base_set(struct event_base *base, struct bufferevent *bufev); + + +/** + Assign a priority to a bufferevent. + + @param bufev a bufferevent struct + @param pri the priority to be assigned + @return 0 if successful, or -1 if an error occurred + */ int bufferevent_priority_set(struct bufferevent *bufev, int pri); + + +/** + Deallocate the storage associated with a bufferevent structure. + + @param bufev the bufferevent structure to be freed. + */ void bufferevent_free(struct bufferevent *bufev); + + +/** + Write data to a bufferevent buffer. + + The bufferevent_write() function can be used to write data to the file descriptor. The + data is appended to the output buffer and written to the descriptor automatically as it + becomes available for writing. + + @param bufev the bufferevent to be written to + @param data a pointer to the data to be written + @param size the length of the data, in bytes + @return 0 if successful, or -1 if an error occurred + @see bufferevent_write_buffer() + */ int bufferevent_write(struct bufferevent *bufev, void *data, size_t size); + + +/** + Write data from an evbuffer to a bufferevent buffer. + + @param bufev the bufferevent to be written to + @param buf the evbuffer to be written + @return 0 if successful, or -1 if an error occurred + @see bufferevent_write() + */ int bufferevent_write_buffer(struct bufferevent *bufev, struct evbuffer *buf); + + +/** + Read data from a bufferevent buffer. + + The bufferevent_read() function is used to read data from the input buffer. + + @param bufev the bufferevent to be read from + @param data pointer to a buffer that will store the data + @param size the size of the data buffer, in bytes + @return the amount of data read, in bytes. + */ size_t bufferevent_read(struct bufferevent *bufev, void *data, size_t size); + +/** + Enable a bufferevent. + + @param bufev the bufferevent to be enabled + @param event any combination of EV_READ | EV_WRITE. + @return 0 if successful, or -1 if an error occurred + @see bufferevent_disable() + */ int bufferevent_enable(struct bufferevent *bufev, short event); + + +/** + Disable a bufferevent. + + @param bufev the bufferevent to be disabled + @param event any combination of EV_READ | EV_WRITE. + @return 0 if successful, or -1 if an error occurred + @see bufferevent_enable() + */ int bufferevent_disable(struct bufferevent *bufev, short event); + + +/** + Set the read and write timeout for a buffered event. + + @param bufev the bufferevent to be modified + @param timeout_read the read timeout + @param timeout_write the write timeout + */ void bufferevent_settimeout(struct bufferevent *bufev, int timeout_read, int timeout_write); + #define EVBUFFER_LENGTH(x) (x)->off #define EVBUFFER_DATA(x) (x)->buffer #define EVBUFFER_INPUT(x) (x)->input #define EVBUFFER_OUTPUT(x) (x)->output + +/** + Allocate storage for a new evbuffer. + + @return a pointer to a newly allocated evbuffer struct, or NULL if an error occurred + */ struct evbuffer *evbuffer_new(void); + + +/** + Deallocate storage for an evbuffer. + + @param pointer to the evbuffer to be freed + */ void evbuffer_free(struct evbuffer *); + + +/** + Expands the available space in an event buffer. + + Expands the available space in the event buffer to at least datlen + + @param buf the event buffer to be expanded + @param datlen the new minimum length requirement + @return 0 if successful, or -1 if an error occurred +*/ int evbuffer_expand(struct evbuffer *, size_t); + + +/** + Append data to the end of an evbuffer. + + @param buf the event buffer to be appended to + @param data pointer to the beginning of the data buffer + @param datlen the number of bytes to be copied from the data buffer + */ int evbuffer_add(struct evbuffer *, const void *, size_t); + + + +/** + Read data from an event buffer and drain the bytes read. + + @param buf the event buffer to be read from + @param data the destination buffer to store the result + @param datlen the maximum size of the destination buffer + @return the number of bytes read + */ int evbuffer_remove(struct evbuffer *, void *, size_t); + + +/** + * Read a single line from an event buffer. + * + * Reads a line terminated by either '\r\n', '\n\r' or '\r' or '\n'. + * The returned buffer needs to be freed by the caller. + * + * @param buffer the evbuffer to read from + * @return pointer to a single line, or NULL if an error occurred + */ char *evbuffer_readline(struct evbuffer *); + + +/** + Move data from one evbuffer into another evbuffer. + + This is a destructive add. The data from one buffer moves into + the other buffer. The destination buffer is expanded as needed. + + @param outbuf the output buffer + @param inbuf the input buffer + @return 0 if successful, or -1 if an error occurred + */ int evbuffer_add_buffer(struct evbuffer *, struct evbuffer *); + + +/** + Append a formatted string to the end of an evbuffer. + + @param buf the evbuffer that will be appended to + @param fmt a format string + @param ... arguments that will be passed to printf(3) + @return 0 if successful, or -1 if an error occurred + */ int evbuffer_add_printf(struct evbuffer *, const char *fmt, ...); + + +/** + Append a va_list formatted string to the end of an evbuffer. + + @param buf the evbuffer that will be appended to + @param fmt a format string + @param ap a varargs va_list argument array that will be passed to vprintf(3) + @return 0 if successful, or -1 if an error occurred + */ int evbuffer_add_vprintf(struct evbuffer *, const char *fmt, va_list ap); + + +/** + Remove a specified number of bytes data from the beginning of an evbuffer. + + @param buf the evbuffer to be drained + @param len the number of bytes to drain from the beginning of the buffer + @return 0 if successful, or -1 if an error occurred + */ void evbuffer_drain(struct evbuffer *, size_t); + + +/** + Write the contents of an evbuffer to a file descriptor. + + The evbuffer will be drained after the bytes have been successfully written. + + @param buffer the evbuffer to be written and drained + @param fd the file descriptor to be written to + @return the number of bytes written, or -1 if an error occurred + @see evbuffer_read() + */ int evbuffer_write(struct evbuffer *, int); + + +/** + Read from a file descriptor and store the result in an evbuffer. + + @param buf the evbuffer to store the result + @param fd the file descriptor to read from + @param howmuch the number of bytes to be read + @return the number of bytes read, or -1 if an error occurred + @see evbuffer_write() + */ int evbuffer_read(struct evbuffer *, int, int); + + +/** + Find a string within an evbuffer. + + @param buffer the evbuffer to be searched + @param what the string to be searched for + @param len the length of the search string + @return a pointer to the beginning of the search string, or NULL if the search failed. + */ u_char *evbuffer_find(struct evbuffer *, const u_char *, size_t); + +/** + Set a callback to invoke when the evbuffer is modified. + + @param buffer the evbuffer to be monitored + @param cb the callback function to invoke when the evbuffer is modified + @param cbarg an argument to be provided to the callback function + */ void evbuffer_setcb(struct evbuffer *, void (*)(struct evbuffer *, size_t, size_t, void *), void *); /* @@ -303,6 +944,16 @@ void evtag_marshal(struct evbuffer *evbuf, uint8_t tag, const void *data, uint32_t len); +/** + Encode an integer and store it in an evbuffer. + + We encode integer's by nibbles; the first nibble contains the number + of significant nibbles - 1; this allows us to encode up to 64-bit + integers. This function is byte-order independent. + + @param evbuf evbuffer to store the encoded number + @param number a 32-bit integer + */ void encode_int(struct evbuffer *evbuf, uint32_t number); void evtag_marshal_int(struct evbuffer *evbuf, uint8_t tag, uint32_t integer); From mark at heily.com Tue Sep 11 20:10:28 2007 From: mark at heily.com (Mark Heily) Date: Wed Sep 12 00:35:08 2007 Subject: [Libevent-users] Re: [PATCH] libevent doxygen API documentation In-Reply-To: <850f7cbe0708090640j61d863epc86f7550fdca799f@mail.gmail.com> References: <1177989356.18996.26.camel@voltaire> <850f7cbe0707302032u42238226tf577d60e23f09705@mail.gmail.com> <1186188038.18023.8.camel@voltaire> <850f7cbe0708090640j61d863epc86f7550fdca799f@mail.gmail.com> Message-ID: <1189555828.12970.9.camel@voltaire> On Thu, 2007-08-09 at 09:40 -0400, Niels Provos wrote: > Hi Mark, > > I am at USENIX Security right now and even less responsive than usual. > I like code documentation. I don't have much experience with > doxygen. However, if you could provide me with a patch against the > existing header files, I am sure that we could start maintaining > doxygen documentation inline with the main code. > Niels, Here is the patch that adds Doxygen documentation comments to the public libevent header files. After applying the patch, you can execute the 'doxygen' command to generate the API reference manual in HTML format. The generated files are created under the 'doxygen/html' subdirectory. This patch applies cleanly to revision 428 of the trunk as of 9/11/2007. Enjoy, Mark ---- Copyright disclaimer: I, Mark Heily, hereby place the following modifications to libevent into the public domain. Hence, these modifications may be freely used and/or redistributed for any purpose with or without attribution and/or other notice. > On 8/3/07, Mark Heily wrote: > > If you like the idea of self-documenting code, I could redo the patch to > > annotate the real event.h and evdns.h, instead of creating a copy in the > > doxygen/ subdirectory. This makes it easier to keep the code and > > documentation in sync in the future; when you change the code, change > > the documentation with it. If the two things are kept separate, they can > > fall out of sync more easily. > > > > > > Best regards, > > > > Mark > > > > On Mon, 2007-07-30 at 20:32 -0700, Niels Provos wrote: > > > Hi Mark, > > > > > > I am slowly catching up on my email back log. Could you please check > > > if your doxygen patch still works against trunk? > > > > > > Thank you, > > > Niels. > > > > > > On 4/30/07, Mark Heily wrote: > > > > Here are the annotated header files and the Doxygen configuration file > > > > that can be used to generate the libevent API reference manual found at > > > > http://naturalc.org/libevent/. > > > > > > > > This patch creates the following files: > > > > > > > > doxygen/ > > > > doxygen/Doxyfile > > > > doxygen/event.h > > > > doxygen/evdns.h > > > > doxygen/evhttp.h > > > > > > > > It also modifies Makefile.am to include these files in the source > > > > tarball when running 'make dist'. > > > > > > > > After applying the patch, go to the doxygen/ subdirectory and run > > > > 'doxygen' to generate the documentation. > > > > > > > > Regards, > > > > > > > > - Mark > > > > > > > > P.S. For legal purposes, > > > > > > > > I, Mark Heily, hereby place the following modifications to libevent into > > > > the public domain. Hence, these modifications may be freely used and/or > > > > redistributed for any purpose with or without attribution and/or other > > > > notice. > > > > > > > > diff -ruN ../libevent.OLD/doxygen/Doxyfile ./doxygen/Doxyfile > > > > --- ../libevent.OLD/doxygen/Doxyfile 1969-12-31 19:00:00.000000000 -0500 > > > > +++ ./doxygen/Doxyfile 2007-04-30 23:02:31.000000000 -0400 > > > > @@ -0,0 +1,226 @@ > > > > +# Doxyfile 1.5.1 > > > > + > > > > +# This file describes the settings to be used by the documentation system > > > > +# doxygen (www.doxygen.org) for a project > > > > +# > > > > -------------- next part -------------- A non-text attachment was scrubbed... Name: libevent-inline-doxygen.patch Type: text/x-patch Size: 58133 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070911/18c5f3bd/libevent-inline-doxygen-0001.bin From Trond.Norbye at Sun.COM Wed Sep 12 04:23:52 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Wed Sep 12 04:24:26 2007 Subject: [Libevent-users] [PATCH] Fix problems in evport.c Message-ID: <46E7A218.80003@sun.com> This patch fix two problems with evport.c on Solaris: 1. The grow-function reallocates the ed_fds array, but ed_pending array may contain pointers to the elements in the ed_fds array. These pointers must be relocated to avoid using freed memory. 2. evport_dispatch does not handle a NULL-timval-pinter (no time-based events are active, wait for I/O). --Trond -------------- next part -------------- A non-text attachment was scrubbed... Name: patch.evport.c Type: text/x-csrc Size: 1704 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070912/c9fe39f5/patch.evport.bin From clayne at anodized.com Sat Sep 15 06:53:12 2007 From: clayne at anodized.com (Christopher Layne) Date: Sat Sep 15 06:53:18 2007 Subject: [Libevent-users] [PATCH] http.c build errors and a segfault (USE_DEBUG only) Message-ID: <20070915105312.GH17673@ns1.anodized.com> Compilation errors in http.c and a segfault during "make verify" when USE_DEBUG is defined. Index: libevent/http.c =================================================================== --- libevent/http.c (revision 429) +++ libevent/http.c (working copy) @@ -1174,7 +1174,7 @@ if (strchr(value, '\r') != NULL || strchr(value, '\n') != NULL || strchr(key, '\r') != NULL || strchr(key, '\n') != NULL) { /* drop illegal headers */ - event_debug(("%s: dropping illegal header\n")); + event_debug(("%s: dropping illegal header\n", __func__)); return (-1); } @@ -1499,7 +1499,7 @@ evcon->fd = bind_socket(evcon->bind_address, 0); if (evcon->fd == -1) { event_debug(("%s: failed to bind to \"%s\"", - __func__, bind_address)); + __func__, evcon->bind_address)); return (-1); } @@ -2439,7 +2439,7 @@ if (ai == NULL) { event_debug(("%s: make_addrinfo: \"%s:%d\"", - __func__, evcon->address, evcon->port)); + __func__, address, port)); return (-1); } From provos at citi.umich.edu Sat Sep 15 11:50:27 2007 From: provos at citi.umich.edu (Niels Provos) Date: Sat Sep 15 11:50:34 2007 Subject: [Libevent-users] [PATCH] http.c build errors and a segfault (USE_DEBUG only) In-Reply-To: <20070915105312.GH17673@ns1.anodized.com> References: <20070915105312.GH17673@ns1.anodized.com> Message-ID: <850f7cbe0709150850m1f819e80x75d1441a73e64b34@mail.gmail.com> Hi Christopher, thank you for the report. This is fixed in trunk now. Niels. On 9/15/07, Christopher Layne wrote: > Compilation errors in http.c and a segfault during "make verify" when > USE_DEBUG is defined. > > Index: libevent/http.c > =================================================================== > --- libevent/http.c (revision 429) > +++ libevent/http.c (working copy) > @@ -1174,7 +1174,7 @@ > if (strchr(value, '\r') != NULL || strchr(value, '\n') != NULL || > strchr(key, '\r') != NULL || strchr(key, '\n') != NULL) { > /* drop illegal headers */ > - event_debug(("%s: dropping illegal header\n")); > + event_debug(("%s: dropping illegal header\n", __func__)); > return (-1); > } > > @@ -1499,7 +1499,7 @@ > evcon->fd = bind_socket(evcon->bind_address, 0); > if (evcon->fd == -1) { > event_debug(("%s: failed to bind to \"%s\"", > - __func__, bind_address)); > + __func__, evcon->bind_address)); > return (-1); > } > > @@ -2439,7 +2439,7 @@ > > if (ai == NULL) { > event_debug(("%s: make_addrinfo: \"%s:%d\"", > - __func__, evcon->address, evcon->port)); > + __func__, address, port)); > return (-1); > } > > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkey.org/mailman/listinfo/libevent-users > > From nickm at freehaven.net Sat Sep 15 14:47:03 2007 From: nickm at freehaven.net (Nick Mathewson) Date: Sat Sep 15 14:47:10 2007 Subject: [Libevent-users] [PATCH] Fix problems in evport.c In-Reply-To: <46E7A218.80003@sun.com> References: <46E7A218.80003@sun.com> Message-ID: <20070915184703.GO22815@totoro.wangafu.net> On Wed, Sep 12, 2007 at 10:23:52AM +0200, Trond Norbye wrote: > This patch fix two problems with evport.c on Solaris: > > 1. The grow-function reallocates the ed_fds array, but ed_pending array > may contain pointers to the elements in the ed_fds array. These pointers > must be relocated to avoid using freed memory. > > 2. evport_dispatch does not handle a NULL-timval-pinter (no time-based > events are active, wait for I/O). Thanks! I've applied this to trunk and to the 1.3 branch. yrs, -- Nick Mathewson -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 652 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070915/e26de9eb/attachment.bin From clayne at anodized.com Tue Sep 18 04:38:53 2007 From: clayne at anodized.com (Christopher Layne) Date: Tue Sep 18 04:38:57 2007 Subject: [Libevent-users] [PATCH] Alter output of test/bench and add option flags Message-ID: <20070918083853.GO17673@ns1.anodized.com> 1. Change output to provide a single line pct done + avg/min/max. 2. Add "-l" flag to support previous style. 3. Add "-x n" flag to specify max loop iterations. In a nutshell, output looks like this: $ debug/test/bench -x 8192 done avg min max 17% 942 653 18997 -cl -- Index: bench.c =================================================================== --- bench.c (revision 433) +++ bench.c (working copy) @@ -55,7 +55,8 @@ static int count, writes, fired; static int *pipes; -static int num_pipes, num_active, num_writes; +static int per_line; +static int num_pipes, num_active, num_writes, num_iter; static struct event *events; @@ -106,7 +107,7 @@ } while (count != fired); gettimeofday(&te, NULL); - if (xcount != count) fprintf(stderr, "Xcount: %d, Rcount: %d\n", xcount, count); + if (xcount != count && per_line) fprintf(stderr, "Xcount: %d, Rcount: %d\n", xcount, count); } timersub(&te, &ts, &te); @@ -122,11 +123,14 @@ struct timeval *tv; int *cp; extern char *optarg; + unsigned long t, min = 0x1 << 31, max = 0, avg = 0; num_pipes = 100; num_active = 1; num_writes = num_pipes; - while ((c = getopt(argc, argv, "n:a:w:")) != -1) { + num_iter = 25; + + while ((c = getopt(argc, argv, "n:a:w:x:l")) != -1) { switch (c) { case 'n': num_pipes = atoi(optarg); @@ -137,6 +141,12 @@ case 'w': num_writes = atoi(optarg); break; + case 'x': + num_iter = atoi(optarg); + break; + case 'l': + per_line++; + break; default: fprintf(stderr, "Illegal argument \"%c\"\n", c); exit(1); @@ -169,13 +179,23 @@ } } - for (i = 0; i < 25; i++) { + fprintf(stdout, "%5s %12s %12s %12s\n", "done", "avg", "min", "max"); + for (i = 1; i <= num_iter; i++) { tv = run_once(); + t = tv->tv_sec * 1000000L + tv->tv_usec; if (tv == NULL) exit(1); - fprintf(stdout, "%ld\n", - tv->tv_sec * 1000000L + tv->tv_usec); + if (per_line) { + fprintf(stdout, "%ld\n", t); + } else { + avg += t; + if (t < min) min = t; + else if (t > max) max = t; + fprintf(stdout, "\r%4d%% %12ld %12ld %12ld", + (100 * i) / num_iter, avg / i, min, max); + } } + fprintf(stdout, "\n"); exit(0); } From clayne at anodized.com Tue Sep 18 04:41:16 2007 From: clayne at anodized.com (Christopher Layne) Date: Tue Sep 18 04:41:18 2007 Subject: [Libevent-users] [PATCH] test/Makefile.am: Correct a relative path issue Message-ID: <20070918084116.GP17673@ns1.anodized.com> 1. event_rpcgen.py will fail to open regress.rpc if building outside the source directory. -cl -- Index: Makefile.am =================================================================== --- Makefile.am (revision 433) +++ Makefile.am (working copy) @@ -18,7 +18,7 @@ bench_SOURCES = bench.c regress.gen.c regress.gen.h: regress.rpc - $(top_srcdir)/event_rpcgen.py regress.rpc || echo "No Python installed" + $(top_srcdir)/event_rpcgen.py ${srcdir}/regress.rpc || echo "No Python installed" DISTCLEANFILES = *~ CLEANFILES = regress.gen.h regress.gen.c From mhvl at sbcglobal.net Tue Sep 18 23:10:42 2007 From: mhvl at sbcglobal.net (M.H.VanLeeuwen) Date: Tue Sep 18 23:15:37 2007 Subject: [Libevent-users] event_add() failure return handling Message-ID: <46F09332.7030906@sbcglobal.net> Hi, When event_add(&ev, &tv) returns -1, what is the proper way to clean up. For example function XYZZY() takes socket fd as an argument XYZZY(int sockfd) { allocate event structure related memory... ... event_set(&(event->event), sockfd, EV_TIMEOUT | EV_WRITE | EV_PERSIST, connected, &(event->event)); ret = event_base_set(event_base, &(event->event)); if (ret == 0) { ret = event_add(&(event->event), &CONNECT_WAIT); } if (ret != 0) { // What is the proper action to take here? return FAIL; } ... return SUCCESS; } ------------- The reason I ask is that it seems event_add() will continue to time for CONNECT_WAIT time even if it returns -1, failure. Shouldn't event_add(), on return of -1, unwind from the timer that it has started? Thanks, Martin From clayne at anodized.com Wed Sep 19 00:20:25 2007 From: clayne at anodized.com (Christopher Layne) Date: Wed Sep 19 00:20:53 2007 Subject: [Libevent-users] event_add() failure return handling In-Reply-To: <46F09332.7030906@sbcglobal.net> References: <46F09332.7030906@sbcglobal.net> Message-ID: <20070919042025.GA23730@ns1.anodized.com> On Tue, Sep 18, 2007 at 10:10:42PM -0500, M.H.VanLeeuwen wrote: > Hi, > > When event_add(&ev, &tv) returns -1, what is the proper way to clean up. > > For example function XYZZY() takes socket fd as an argument > > XYZZY(int sockfd) > { > allocate event structure related memory... > ... > event_set(&(event->event), sockfd, EV_TIMEOUT | EV_WRITE | > EV_PERSIST, connected, &(event->event)); > ret = event_base_set(event_base, &(event->event)); > > if (ret == 0) > { > ret = event_add(&(event->event), &CONNECT_WAIT); > } > > if (ret != 0) > { > // What is the proper action to take here? > return FAIL; > } > ... > return SUCCESS; > } The only way to receive a non-zero retval from event_add is if the underlying event notification mechanism returns a non-zero value to event_add. In order to determine which event mechanism that is, we need more information like which OS you're experiencing this under and/or the particular event mechanism you're using (set the following shell variable before executing your code: EVENT_SHOW_METHOD=1). Without knowing more than that all one can say is that if event_add() returns -1, it is programming error, somewhere. I speculate possibly your fd is invalid or previously closed or something else is wrong. > The reason I ask is that it seems event_add() will continue to time for > CONNECT_WAIT time > even if it returns -1, failure. Shouldn't event_add(), on return of -1, > unwind from the timer that > it has started? This is valid. However it's kind of a rare case. -cl From slamb at slamb.org Wed Sep 19 01:15:24 2007 From: slamb at slamb.org (Scott Lamb) Date: Wed Sep 19 01:15:28 2007 Subject: [Libevent-users] event_base_loop_break()? Message-ID: <46F0B06C.5090903@slamb.org> While playing with pyevent, I saw this code: def abort(): """Abort event dispatch loop.""" cdef extern int event_gotsig cdef extern int (*event_sigcb)() event_sigcb = __event_sigcb event_gotsig = 1 This is used in exception handling - if a callback throws an exception, it does this to propogate the exception through immediately (breaking out of the loop without running any more callbacks). This off-label use of a deprecated libevent interface is confusing, and I suspect it can interact badly with the more modern signal handling interface. I propose instead that libevent have a event_base_loop_break() and event_loop_break(). (Or whatever you want them called.) They'd differ from event_{base_,}loop_exit() in that they would *immediately* abort the loop without finishing the iteration (i.e., sooner than event_base_loop_exit({.tv_sec=0, .tv_usec=0})). They'd be analogous to the C "break;" statement. Like event_loop_exit(), the next dispatch would be unaffected. Feelings? I'd be happy to work up a patch and unit test. Best regards, Scott [1] - Well, not quite, because there's a bug. But it's clearly intended to, and with a small patch it does. -- Scott Lamb From mhvl at sbcglobal.net Wed Sep 19 01:24:47 2007 From: mhvl at sbcglobal.net (M.H.VanLeeuwen) Date: Wed Sep 19 01:29:31 2007 Subject: [Libevent-users] event_add() failure return handling In-Reply-To: <20070919042025.GA23730@ns1.anodized.com> References: <46F09332.7030906@sbcglobal.net> <20070919042025.GA23730@ns1.anodized.com> Message-ID: <46F0B29F.7080307@sbcglobal.net> Christopher Layne wrote: > On Tue, Sep 18, 2007 at 10:10:42PM -0500, M.H.VanLeeuwen wrote: > >> Hi, >> >> When event_add(&ev, &tv) returns -1, what is the proper way to clean up. >> >> For example function XYZZY() takes socket fd as an argument >> >> XYZZY(int sockfd) >> { >> allocate event structure related memory... >> ... >> event_set(&(event->event), sockfd, EV_TIMEOUT | EV_WRITE | >> EV_PERSIST, connected, &(event->event)); >> ret = event_base_set(event_base, &(event->event)); >> >> if (ret == 0) >> { >> ret = event_add(&(event->event), &CONNECT_WAIT); >> } >> >> if (ret != 0) >> { >> // What is the proper action to take here? >> return FAIL; >> } >> ... >> return SUCCESS; >> } >> > > The only way to receive a non-zero retval from event_add is if the > underlying event notification mechanism returns a non-zero value > to event_add. In order to determine which event mechanism that is, > we need more information like which OS you're experiencing this under > and/or the particular event mechanism you're using (set the following > shell variable before executing your code: EVENT_SHOW_METHOD=1). > > Without knowing more than that all one can say is that if event_add() > returns -1, it is programming error, somewhere. I speculate possibly > your fd is invalid or previously closed or something else is wrong. > > Hi Chris, Linux 2.6 kernel, on _rare_ occasions I get errno=2 back from epoll_add(). #define ENOENT 2 /* No such file or directory */ I'd have expected EBADF (9) if the sockfd was invalid. I've not gone to look at why this is being returned yet, any ideas? So the question really is, does one need to call event_del() to cleanup or should the event_add() cleanup the timer before returning an error? The change/fix seems simple enough. Agreed, the occurrence is quite rare indeed, and likely a bug in my code. Thanks, Martin >> The reason I ask is that it seems event_add() will continue to time for >> CONNECT_WAIT time >> even if it returns -1, failure. Shouldn't event_add(), on return of -1, >> unwind from the timer that >> it has started? >> > > This is valid. However it's kind of a rare case. > > -cl > From Bob.Maccione at hilton.com Wed Sep 19 12:55:27 2007 From: Bob.Maccione at hilton.com (Bob Maccione) Date: Wed Sep 19 12:56:18 2007 Subject: [Libevent-users] burst mode losing txns? Message-ID: <88CD683992DCAF4C9D443DF8CA005D660325B67C@hwmxmsg03.hotels.ad.hilton.com> I'm trying to make a small test case but thought I'd throw out the problem. we multiplex a lot of sessions over a single connection. when we burst across the session we seem to be losing messages (messages are null terminated). I put a print at the read() ( we are using buffered events ) and messages are just not being read. This is on solaris 8 (sparc) and using gcc as the compilier. Anyone seen anything like this before? thx. bob -------------- next part -------------- An HTML attachment was scrubbed... URL: http://monkeymail.org/archives/libevent-users/attachments/20070919/c4c6a698/attachment.htm From nickm at freehaven.net Wed Sep 19 15:07:36 2007 From: nickm at freehaven.net (Nick Mathewson) Date: Wed Sep 19 15:08:03 2007 Subject: [Libevent-users] Win32 signal handling (and other win32 issues) Message-ID: <20070919190736.GS22825@totoro.wangafu.net> Skipped content of type multipart/mixed-------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 652 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070919/c2bdd2b4/attachment.bin From Trond.Norbye at Sun.COM Thu Sep 20 07:43:59 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Thu Sep 20 07:44:23 2007 Subject: [Libevent-users] [PATCH] Fix syntax error in autogen.sh Message-ID: <46F25CFF.6050907@sun.com> /bin/sh does not recognize == as a valid test operator, but /bin/bash does... --Trond -------------- next part -------------- A non-text attachment was scrubbed... Name: autogen.sh.patch Type: text/x-patch Size: 273 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070920/94de64f0/autogen.sh.bin From Trond.Norbye at Sun.COM Thu Sep 20 07:52:31 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Thu Sep 20 07:52:58 2007 Subject: [Libevent-users] [PATCH] Do not call gettime in timeout_process if the timetree is empty Message-ID: <46F25EFF.9060209@sun.com> The result of gettime is not used if the timetree is empty (and might cause a context switch to get the system clock). --Trond -------------- next part -------------- A non-text attachment was scrubbed... Name: event.c.patch Type: text/x-patch Size: 1195 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070920/192e129b/event.c-0001.bin From clayne at anodized.com Thu Sep 20 08:00:38 2007 From: clayne at anodized.com (Christopher Layne) Date: Thu Sep 20 08:00:40 2007 Subject: [Libevent-users] [PATCH] Do not call gettime in timeout_process if the timetree is empty In-Reply-To: <46F25EFF.9060209@sun.com> References: <46F25EFF.9060209@sun.com> Message-ID: <20070920120037.GB23730@ns1.anodized.com> On Thu, Sep 20, 2007 at 01:52:31PM +0200, Trond Norbye wrote: > The result of gettime is not used if the timetree is empty (and might > cause a context switch to get the system clock). > > --Trond > Index: event.c > =================================================================== > --- event.c (revision 440) > +++ event.c (working copy) > @@ -804,24 +804,26 @@ > void > timeout_process(struct event_base *base) > { > - struct timeval now; > - struct event *ev, *next; > + if (!RB_EMPTY(&base->timetree)) { > + struct timeval now; > + struct event *ev, *next; Why not just return if RB_EMPTY() is true rather than adding another level of indention? Other than that, I also noticed this but didn't consider it as anything significant. It has never once showed up as any significant source of cycles in profiling either. -cl From msf at kisoku.net Thu Sep 20 08:11:16 2007 From: msf at kisoku.net (Mathieu Sauve-Frankel) Date: Thu Sep 20 08:11:52 2007 Subject: [Libevent-users] [PATCH] Fix syntax error in autogen.sh In-Reply-To: <46F25CFF.6050907@sun.com> References: <46F25CFF.6050907@sun.com> Message-ID: <20070920121116.GB84@shingen.kisoku.net> On Thu, Sep 20, 2007 at 01:43:59PM +0200, Trond Norbye wrote: > /bin/sh does not recognize == as a valid test operator, but /bin/bash > does... Don't you think it's perhaps a more sane and portable approach to just fix the erroneous operator than change to a non-standard shell ? Making bash a build dependency for libevent is the wrong approach imo. -- Mathieu Sauve-Frankel From Magne.Mahre at Sun.COM Thu Sep 20 08:20:19 2007 From: Magne.Mahre at Sun.COM (=?ISO-8859-1?Q?Magne_M=E6hre?=) Date: Thu Sep 20 08:21:06 2007 Subject: [Libevent-users] [PATCH] Fix syntax error in autogen.sh In-Reply-To: <46F25CFF.6050907@sun.com> References: <46F25CFF.6050907@sun.com> Message-ID: <46F26583.4020701@sun.com> Trond Norbye wrote: > /bin/sh does not recognize == as a valid test operator, but /bin/bash > does... Changing to /bin/bash isn't a good solution, since you're not guaranteed to have bash on every system (nor that it's in /bin) I would suggest to have the script Bourne shell compliant instead : SYSNAME=`uname` if [ "$SYSNAME" = "Darwin" ] ; then LIBTOOLIZE=glibtoolize fi --Magne From Trond.Norbye at Sun.COM Thu Sep 20 09:14:51 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Thu Sep 20 09:15:13 2007 Subject: [Libevent-users] [PATCH] Do not call gettime in timeout_process if the timetree is empty In-Reply-To: <20070920120037.GB23730@ns1.anodized.com> References: <46F25EFF.9060209@sun.com> <20070920120037.GB23730@ns1.anodized.com> Message-ID: <46F2724B.2070200@sun.com> Christopher Layne wrote: > >> Index: event.c >> =================================================================== >> --- event.c (revision 440) >> +++ event.c (working copy) >> @@ -804,24 +804,26 @@ >> void >> timeout_process(struct event_base *base) >> { >> - struct timeval now; >> - struct event *ev, *next; >> + if (!RB_EMPTY(&base->timetree)) { >> + struct timeval now; >> + struct event *ev, *next; >> > > Why not just return if RB_EMPTY() is true rather than adding another level > of indention? Some people (I'm not one of them) dislikes multiple return statements from a function, so I just added the extra level to avoid annoying them ;-) > Other than that, I also noticed this but didn't consider it as > anything significant. It has never once showed up as any significant source > of cycles in profiling either. > I noticed that I had a huge number of calls to this function when I ran "truss -c" a couple of seconds on my program, so I would like to reduce the number of unnecessary context switches. Trond From Trond.Norbye at Sun.COM Thu Sep 20 09:23:32 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Thu Sep 20 09:24:03 2007 Subject: [Libevent-users] [PATCH] Fix syntax error in autogen.sh In-Reply-To: <46F26583.4020701@sun.com> References: <46F25CFF.6050907@sun.com> <46F26583.4020701@sun.com> Message-ID: <46F27454.9010100@sun.com> Magne M?hre wrote: > Changing to /bin/bash isn't a good solution, since you're not > guaranteed to have bash on every system (nor that it's in /bin) > > I would suggest to have the script Bourne shell compliant instead : > > SYSNAME=`uname` > if [ "$SYSNAME" = "Darwin" ] ; then > LIBTOOLIZE=glibtoolize > fi You're right, thats a much better solution (I just assumed it would be bash since I've heard that most Linux distributions provides /bin/sh as a link to bash). Trond From hannah at schlund.de Thu Sep 20 10:46:18 2007 From: hannah at schlund.de (Hannah Schroeter) Date: Thu Sep 20 10:46:49 2007 Subject: [Libevent-users] [PATCH] Fix syntax error in autogen.sh In-Reply-To: <46F27454.9010100@sun.com> References: <46F25CFF.6050907@sun.com> <46F26583.4020701@sun.com> <46F27454.9010100@sun.com> Message-ID: <20070920144618.GA28945@schlund.de> Hi! On Thu, Sep 20, 2007 at 03:23:32PM +0200, Trond Norbye wrote: >Magne M?hre wrote: >>Changing to /bin/bash isn't a good solution, since you're not >>guaranteed to have bash on every system (nor that it's in /bin) >>I would suggest to have the script Bourne shell compliant instead : >>SYSNAME=`uname` >>if [ "$SYSNAME" = "Darwin" ] ; then >> LIBTOOLIZE=glibtoolize >>fi >You're right, thats a much better solution (I just assumed it would be >bash since I've heard that most Linux distributions provides /bin/sh as >a link to bash). Not all the world is Linux. I'd suggest if [ X"$SYSNAME" = X"Darwin" ] ... to be really safe, btw. >Trond Kind regards, Hannah. From nickm at freehaven.net Thu Sep 20 14:26:58 2007 From: nickm at freehaven.net (Nick Mathewson) Date: Thu Sep 20 14:27:12 2007 Subject: [Libevent-users] [PATCH] Do not call gettime in timeout_process if the timetree is empty In-Reply-To: <46F2724B.2070200@sun.com> References: <46F25EFF.9060209@sun.com> <20070920120037.GB23730@ns1.anodized.com> <46F2724B.2070200@sun.com> Message-ID: <20070920182658.GX22825@totoro.wangafu.net> On Thu, Sep 20, 2007 at 03:14:51PM +0200, Trond Norbye wrote: [...] > > > >Why not just return if RB_EMPTY() is true rather than adding another level > >of indention? > Some people (I'm not one of them) dislikes multiple return statements > from a function, so I just added the extra level to avoid annoying them ;-) I'm not one of those people, so I'm rewriting your patch to a simple "if (RB_EMPTY(&base->timetree)) return;" and checking it in. ;) yrs, -- Nick Mathewson -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 652 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070920/bd84850e/attachment.bin From estanisgeyer at hotmail.com Thu Sep 20 19:12:56 2007 From: estanisgeyer at hotmail.com (Marcelo Estanislau Geyer) Date: Thu Sep 20 19:13:18 2007 Subject: [Libevent-users] Undefined reference Message-ID: Hi, I'm development small program in C++ on Linux (Fedora 7 and Kdevelop). When compiling the program, is appearing the following message: undefined reference to `event_init' I have add header event.h, but I am with difficulties to work with this library due to these errors. Thanks, Marcelo Estanislau Brazil. _________________________________________________________________ Receba GR?TIS as ?ltimas novidades do esporte direto no seu Messenger! http://signup.alerts.live.com/alerts/login.do?PINID=37485679&returnURL=http://www.nivea.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: http://monkeymail.org/archives/libevent-users/attachments/20070920/df2af7da/attachment.htm From slamb at slamb.org Thu Sep 20 19:40:38 2007 From: slamb at slamb.org (Scott Lamb) Date: Thu Sep 20 19:40:37 2007 Subject: [Libevent-users] Undefined reference In-Reply-To: References: Message-ID: <46F304F6.9050504@slamb.org> Marcelo Estanislau Geyer wrote: > Hi, > > I'm development small program in C++ on Linux (Fedora 7 and Kdevelop). > When compiling the program, is appearing the following message: > > undefined reference to `event_init' > > I have add header event.h, but I am with difficulties to work with this > library due to these errors. The header is used at compile-time. 'undefined reference' is a link-time error. You need to link in -levent as well. > Thanks, > > Marcelo Estanislau > Brazil. > > ------------------------------------------------------------------------ > Receba GR?TIS as ?ltimas novidades do esporte direto no seu Messenger! > Assine j?! > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkey.org/mailman/listinfo/libevent-users From provos at citi.umich.edu Tue Sep 25 00:10:43 2007 From: provos at citi.umich.edu (Niels Provos) Date: Tue Sep 25 00:11:08 2007 Subject: [Libevent-users] libevent-1.3e released Message-ID: <850f7cbe0709242110n5c070e34nee6fd96ae48bba7c@mail.gmail.com> Hi everyone, I am pleased to announce the release of libevent-1.3e. This is mostly a bug fix release. Here is a list of changes: - demote most http warnings to debug messages - Fix compilation on Solaris; from Magne Mahre - Add a "Date" header to HTTP responses when it's missing, as required by HTTP 1.1. Original Patch from Ralph Moritz. - Fix a memory leak in which failed HTTP connections whould not free the request object. - Fix a memory leak in the DNS server. - Handle NULL timeouts correctly on Solaris; from Trond Norbye - Recalculate pending events properly when reallocating event array on Solaris; from Trond Norbye. You can download libevent from http://www.monkey.org/~provos/libevent/ If you encounter any problems or would like to submit patches, let either Nick Mathewson or myself know. Thanks, Niels. From Trond.Norbye at Sun.COM Tue Sep 25 04:12:07 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Tue Sep 25 04:12:23 2007 Subject: [Libevent-users] [PATCH] Add support for evport in test/test.sh Message-ID: <46F8C2D7.2030502@sun.com> The attached patch will add a test case for the event port implementation. Trond -------------- next part -------------- A non-text attachment was scrubbed... Name: test.sh.patch Type: text/x-patch Size: 470 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070925/8f69cc15/test.sh.bin From Trond.Norbye at Sun.COM Tue Sep 25 06:12:43 2007 From: Trond.Norbye at Sun.COM (Trond Norbye) Date: Tue Sep 25 06:13:01 2007 Subject: [Libevent-users] Question: Library naming Message-ID: <46F8DF1B.4040000@sun.com> I have intalled libevent 1.3c and 1.3d on my machine, and I have some questions about the naming used for libevent. In my lib-directory I get the following: lrwxrwxrwx 1 bin bin 22 Sep 24 21:09 libevent-1.3c.so.1 -> libevent-1.3c.so.1.0.3 -rwxr-xr-x 1 bin bin 160824 Sep 24 21:09 libevent-1.3c.so.1.0.3 lrwxrwxrwx 1 bin bin 22 Sep 24 19:21 libevent-1.3d.so.1 -> libevent-1.3d.so.1.0.3 -rwxr-xr-x 1 bin bin 303856 Sep 24 19:21 libevent-1.3d.so.1.0.3 lrwxrwxrwx 1 bin bin 22 Sep 24 19:21 libevent.so -> libevent-1.3d.so.1.0.3 When I look at the dynamic section in the libraries I see that it records libevent-1.3[cd].so.1 as the soname, so if I link my application with libevent it will require the same version of libevent to be located at runtime. I thought that it was normal to name the libraries like lib.so... (eg: libevent.so.1.3.4) and create symbolic links so the application may pick up the newest version of the library (with the correct ABI) without re-linking the application. Is there a good reason for not doing so? Trond (I looked in the archive and found http://monkeymail.org/archives/libevent-users/2006-March/000114.html, but I did not find a response to the question). From clayne at anodized.com Wed Sep 26 08:16:23 2007 From: clayne at anodized.com (Christopher Layne) Date: Wed Sep 26 08:16:39 2007 Subject: [Libevent-users] [PATCH] libevent/event.3: small cleanup and additional notes Message-ID: <20070926121623.GA988@ns1.anodized.com> It's really difficult to have a diff explain manpage changes due to the nature of ROFF markup, etc. Positional changes: Moved the opening paragraphs about signal specific issues to right under the signal_add(), signal_set() section, since they're related. Moved the opening paragraphs about event_loop(), etc. to the bottom of the DESCRIPTION section since they're more ancillary than immediately pertinent. Moved the parts about manipulating underlying handlers (EVENT_METHOD, etc.) to the bottom, right before "RETURN VALUES" w/ the new heading "ADDITIONAL NOTES". Wording changes: Before: The function fn will be called with the file descriptor that triggered the event and the type of event which will be either EV_TIMEOUT, EV_SIGNAL, EV_READ, or EV_WRITE. The additional flag EV_PERSIST makes an event_add() persistent until event_del() has been called. After: The function fn will be called with the file descriptor that triggered the event and the type of event which will be either EV_TIMEOUT, EV_SIGNAL, EV_READ, or EV_WRITE. Additionally, an event which has registered interest in more than one of the preceeding events, via bitwise-OR to event_set(), can provide it's callback function with a bitwise-OR of more than one triggered event. The additional flag EV_PERSIST makes an event_add() persistent until event_del() has been called. Rationale for this additional wording is related to situations in which: event_set(ev, fd, EVREAD | EV_WRITE, cb, cbd); can result in cb() being called with event == 6 (0x2 | 0x4). A perfect example of which is non-blocking connect() w/ pending error: $ ./ev 127.0.0.1 7 connect: Operation now in progress ev_cb: fd == 3, event == 4 connect: Success $ ./ev 127.0.0.1 73 connect: Operation now in progress ev_cb: fd == 3, event == 6 connect: Connection refused Not really a huge deal, but documenting it as perfectly legal since the original wording implied exclusivity among event types passed to the callback when in reality it's a mask. This will bite people who use one function for both and then try to switch/case it. -cl -------------- next part -------------- Index: libevent/event.3 =================================================================== --- libevent/event.3 (revision 454) +++ libevent/event.3 (working copy) @@ -208,51 +208,6 @@ This function only returns on error, and should replace the event core of the application program. .Pp -In order to avoid races in signal handlers, the -.Nm event -API provides two variables: -.Va event_sigcb -and -.Va event_gotsig . -A signal handler -sets -.Va event_gotsig -to indicate that a signal has been received. -The application sets -.Va event_sigcb -to a callback function. -After the signal handler sets -.Va event_gotsig , -.Nm event_dispatch -will execute the callback function to process received signals. -The callback returns 1 when no events are registered any more. -It can return \-1 to indicate an error to the -.Nm event -library, causing -.Fn event_dispatch -to terminate with -.Va errno -set to -.Er EINTR . -.Pp -The -.Nm event_loop -function provides an interface for single pass execution of pending -events. -The flags -.Va EVLOOP_ONCE -and -.Va EVLOOP_NONBLOCK -are recognized. -The -.Nm event_loopexit -function allows the loop to be terminated after some amount of time -has passed. -The parameter indicates the time after which the loop should terminate. -.Pp -It is the responsibility of the caller to provide these functions with -pre-allocated event structures. -.Pp The function .Fn event_set prepares the event structure @@ -291,6 +246,11 @@ .Va EV_READ , or .Va EV_WRITE . +Additionally, an event which has registered interest in more than one of the +preceeding events, via bitwise-OR to +.Fn event_set , +can provide it's callback function with a bitwise-OR of more than one triggered +event. The additional flag .Va EV_PERSIST makes an @@ -356,6 +316,59 @@ If the event has already executed or has never been added the call will have no effect. .Pp +The functions +.Fn evtimer_set , +.Fn evtimer_add , +.Fn evtimer_del , +.Fn evtimer_initialized , +and +.Fn evtimer_pending +are abbreviations for common situations where only a timeout is required. +The file descriptor passed will be \-1, and the event type will be +.Va EV_TIMEOUT . +.Pp +The functions +.Fn signal_set , +.Fn signal_add , +.Fn signal_del , +.Fn signal_initialized , +and +.Fn signal_pending +are abbreviations. +The event type will be a persistent +.Va EV_SIGNAL . +That means +.Fn signal_set +adds +.Va EV_PERSIST . +.Pp +In order to avoid races in signal handlers, the +.Nm event +API provides two variables: +.Va event_sigcb +and +.Va event_gotsig . +A signal handler +sets +.Va event_gotsig +to indicate that a signal has been received. +The application sets +.Va event_sigcb +to a callback function. +After the signal handler sets +.Va event_gotsig , +.Nm event_dispatch +will execute the callback function to process received signals. +The callback returns 1 when no events are registered any more. +It can return \-1 to indicate an error to the +.Nm event +library, causing +.Fn event_dispatch +to terminate with +.Va errno +set to +.Er EINTR . +.Pp The function .Fn event_once is similar to @@ -388,45 +401,24 @@ .Fn event_initialized macro can be used to check if an event has been initialized. .Pp -The functions -.Fn evtimer_set , -.Fn evtimer_add , -.Fn evtimer_del , -.Fn evtimer_initialized , +The +.Nm event_loop +function provides an interface for single pass execution of pending +events. +The flags +.Va EVLOOP_ONCE and -.Fn evtimer_pending -are abbreviations for common situations where only a timeout is required. -The file descriptor passed will be \-1, and the event type will be -.Va EV_TIMEOUT . +.Va EVLOOP_NONBLOCK +are recognized. +The +.Nm event_loopexit +function allows the loop to be terminated after some amount of time +has passed. +The parameter indicates the time after which the loop should terminate. .Pp -The functions -.Fn signal_set , -.Fn signal_add , -.Fn signal_del , -.Fn signal_initialized , -and -.Fn signal_pending -are abbreviations. -The event type will be a persistent -.Va EV_SIGNAL . -That means -.Fn signal_set -adds -.Va EV_PERSIST . +It is the responsibility of the caller to provide these functions with +pre-allocated event structures. .Pp -It is possible to disable support for -.Va epoll , kqueue , devpoll , poll -or -.Va select -by setting the environment variable -.Va EVENT_NOEPOLL , EVENT_NOKQUEUE , EVENT_NODEVPOLL , EVENT_NOPOLL -or -.Va EVENT_NOSELECT , -respectively. -By setting the environment variable -.Va EVENT_SHOW_METHOD , -.Nm libevent -displays the kernel notification method that it uses. .Sh EVENT PRIORITIES By default .Nm libevent @@ -562,6 +554,20 @@ check .Va event.h for the public interfaces. +.Sh ADDITIONAL NOTES +It is possible to disable support for +.Va epoll , kqueue , devpoll , poll +or +.Va select +by setting the environment variable +.Va EVENT_NOEPOLL , EVENT_NOKQUEUE , EVENT_NODEVPOLL , EVENT_NOPOLL +or +.Va EVENT_NOSELECT , +respectively. +By setting the environment variable +.Va EVENT_SHOW_METHOD , +.Nm libevent +displays the kernel notification method that it uses. .Sh RETURN VALUES Upon successful completion .Fn event_add From estanisgeyer at hotmail.com Wed Sep 26 20:32:09 2007 From: estanisgeyer at hotmail.com (Marcelo Estanislau Geyer) Date: Wed Sep 26 20:32:21 2007 Subject: [Libevent-users] libevent and C++ Message-ID: Hi boys and girls, Somebody a have examples of use of the library libevent in C++ or applications, would like to see as to use concepts of OO with libevent. Thanks, Marcelo. _________________________________________________________________ Receba GR?TIS as mensagens do Messenger no seu celular quando voc? estiver offline. Conhe?a o MSN Mobile! http://mobile.live.com/signup/signup2.aspx?lc=pt-br -------------- next part -------------- An HTML attachment was scrubbed... URL: http://monkeymail.org/archives/libevent-users/attachments/20070927/0d30a3bf/attachment.htm From clayne at anodized.com Thu Sep 27 01:50:41 2007 From: clayne at anodized.com (Christopher Layne) Date: Thu Sep 27 01:51:03 2007 Subject: [Libevent-users] [PATCH] Add autoconf/make functionality for --disable-dns, --disable-http, and --disable-bevents Message-ID: <20070927055041.GA18876@ns1.anodized.com> $ ./configure --help [...] Optional Features: [...] --enable-dns build with support for dns layer [default=yes] --enable-http build with support for http layer [default=yes] --enable-bevents build with support for buffer events [default=yes] Changes: 1. This required me to move buffer_* and evbuffer_* function declarations that were in event.h to a new file, evbuffer.h. Also, it looks like buffer.c contains ev_buffer_* functions and evbuffer.c contains buffer_* functions. This was like this before so I just tried to keep things consistent overall when creating a new header file and went with evbuffer.h. The flip-flop can be changed later. Also added evbuffer.h include to various http and bufferevents specific modules/headers that required them. 2. This required creating test/regress_buffer.c and moving bevents regress specific code into that module. Calls to higher level regress suite collection functions are conditionally ifdef'd via HAVE_EVENT_DNS, HAVE_EVENT_HTTP, etc. (which configure takes care of). 3. In both cases of above, the actual conditional building of modules is handled via ifdef's within Makefile.am that configure takes care of. 4. Modified configure.in to not bother doing Fortran, C++, or ObjC specific tests. Libtool likes to try it's own checks as well, but I just redefined those with simple null macros. 5. Throughout this all: substantially increased my derision for GNU auto* tools. Pros: 1. Significantly smaller libevent library footprint but the ability to include everything normally. 2. Default, nothing changes, all API layers are enabled per normal. 3. Couple of useful macros added to configure.in which should make adding any other enable/disable and build checks quicker. Cons: 1. http code is highly dependent on bufferevents code. As such, one cannot use "--enable-bufferevents=no" w/ "--enable-http=no". If bufferevent code is disabled, http code must be disabled. 2. rpc code (which AFAICT is regress testing specific) is tied with http code and shares the same characteristics of above. Builds+size+make verify checks: $ set=( "--disable-none" \ "--disable-dns" \ "--disable-http" \ "--disable-dns --disable-http" \ "--disable-bevents --disable-http" \ "--disable-bevents --disable-http --disable-dns" ); \ a=${#set[*]}; i=0; while [[ $i -lt $a ]]; do f="${set[i++]}"; echo $f; \ (./configure $f && make clean && make) 1>/tmp/error.out 2>&1 \ || (cat /tmp/error.out && break); \ size .libs/libevent.so; \ make verify 2>&1 | egrep FAIL && break; \ printf "\n"; done --disable-none text data bss dec hex filename 67115 1120 6904 75139 12583 .libs/libevent.so --disable-dns text data bss dec hex filename 48804 1040 6328 56172 db6c .libs/libevent.so --disable-http text data bss dec hex filename 45589 840 708 47137 b821 .libs/libevent.so --disable-dns --disable-http text data bss dec hex filename 26603 728 132 27463 6b47 .libs/libevent.so --disable-bevents --disable-http text data bss dec hex filename 37882 744 704 39330 99a2 .libs/libevent.so --disable-bevents --disable-http --disable-dns text data bss dec hex filename 18969 628 128 19725 4d0d .libs/libevent.so This patch is 50k, but is mostly just -+ of moving buffer-specific code from one file to another and the such. Attached as bzip2 here, and also raw at this url: http://www.anodized.com/~clayne/libevent.2007092600.diff -cl -------------- next part -------------- A non-text attachment was scrubbed... Name: libevent.2007092600.diff.bz2 Type: application/octet-stream Size: 10190 bytes Desc: not available Url : http://monkeymail.org/archives/libevent-users/attachments/20070926/3ad9ad30/libevent.2007092600.diff-0001.obj From provos at citi.umich.edu Thu Sep 27 11:31:32 2007 From: provos at citi.umich.edu (Niels Provos) Date: Thu Sep 27 11:31:54 2007 Subject: [Libevent-users] [PATCH] Add autoconf/make functionality for --disable-dns, --disable-http, and --disable-bevents In-Reply-To: <20070927055041.GA18876@ns1.anodized.com> References: <20070927055041.GA18876@ns1.anodized.com> Message-ID: <850f7cbe0709270831r4153318o6336aeced7e16e6@mail.gmail.com> Hi Christopher, I am not sure if this is necessarily the right way to go for a library, esp if it can impact backwards compatibility for bufferevents. As for reducing the size of the library, do you really think that 30K make a difference these days? Niels. On 9/26/07, Christopher Layne wrote: > $ ./configure --help > [...] > Optional Features: > [...] > --enable-dns build with support for dns layer [default=yes] > --enable-http build with support for http layer [default=yes] > --enable-bevents build with support for buffer events [default=yes] > > Changes: > > 1. This required me to move buffer_* and evbuffer_* function declarations > that were in event.h to a new file, evbuffer.h. Also, it looks like > buffer.c contains ev_buffer_* functions and evbuffer.c contains > buffer_* functions. This was like this before so I just tried to keep > things consistent overall when creating a new header file and went with > evbuffer.h. The flip-flop can be changed later. Also added evbuffer.h include > to various http and bufferevents specific modules/headers that required them. > > 2. This required creating test/regress_buffer.c and moving bevents > regress specific code into that module. Calls to higher level regress > suite collection functions are conditionally ifdef'd via HAVE_EVENT_DNS, > HAVE_EVENT_HTTP, etc. (which configure takes care of). > > 3. In both cases of above, the actual conditional building of modules > is handled via ifdef's within Makefile.am that configure takes care of. > > 4. Modified configure.in to not bother doing Fortran, C++, or ObjC specific > tests. Libtool likes to try it's own checks as well, but I just redefined > those with simple null macros. > > 5. Throughout this all: substantially increased my derision for GNU auto* > tools. > > Pros: > > 1. Significantly smaller libevent library footprint but the ability to > include everything normally. > 2. Default, nothing changes, all API layers are enabled per normal. > 3. Couple of useful macros added to configure.in which should make adding > any other enable/disable and build checks quicker. > > Cons: > > 1. http code is highly dependent on bufferevents code. As such, one cannot > use "--enable-bufferevents=no" w/ "--enable-http=no". If bufferevent code > is disabled, http code must be disabled. > 2. rpc code (which AFAICT is regress testing specific) is tied with http > code and shares the same characteristics of above. > > Builds+size+make verify checks: > > $ set=( "--disable-none" \ > "--disable-dns" \ > "--disable-http" \ > "--disable-dns --disable-http" \ > "--disable-bevents --disable-http" \ > "--disable-bevents --disable-http --disable-dns" ); \ > a=${#set[*]}; i=0; while [[ $i -lt $a ]]; do f="${set[i++]}"; echo $f; \ > (./configure $f && make clean && make) 1>/tmp/error.out 2>&1 \ > || (cat /tmp/error.out && break); \ > size .libs/libevent.so; \ > make verify 2>&1 | egrep FAIL && break; \ > printf "\n"; done > > --disable-none > text data bss dec hex filename > 67115 1120 6904 75139 12583 .libs/libevent.so > > --disable-dns > text data bss dec hex filename > 48804 1040 6328 56172 db6c .libs/libevent.so > > --disable-http > text data bss dec hex filename > 45589 840 708 47137 b821 .libs/libevent.so > > --disable-dns --disable-http > text data bss dec hex filename > 26603 728 132 27463 6b47 .libs/libevent.so > > --disable-bevents --disable-http > text data bss dec hex filename > 37882 744 704 39330 99a2 .libs/libevent.so > > --disable-bevents --disable-http --disable-dns > text data bss dec hex filename > 18969 628 128 19725 4d0d .libs/libevent.so > > > This patch is 50k, but is mostly just -+ of moving buffer-specific code from > one file to another and the such. Attached as bzip2 here, and also raw at > this url: http://www.anodized.com/~clayne/libevent.2007092600.diff > > -cl > > _______________________________________________ > Libevent-users mailing list > Libevent-users@monkey.org > http://monkey.org/mailman/listinfo/libevent-users > > > From clayne at anodized.com Thu Sep 27 18:53:51 2007 From: clayne at anodized.com (Christopher Layne) Date: Thu Sep 27 18:53:56 2007 Subject: [Libevent-users] [PATCH] Add autoconf/make functionality for --disable-dns, --disable-http, and --disable-bevents In-Reply-To: <850f7cbe0709270831r4153318o6336aeced7e16e6@mail.gmail.com> References: <20070927055041.GA18876@ns1.anodized.com> <850f7cbe0709270831r4153318o6336aeced7e16e6@mail.gmail.com> Message-ID: <20070927225351.GB18876@ns1.anodized.com> On Thu, Sep 27, 2007 at 08:31:32AM -0700, Niels Provos wrote: > Hi Christopher, > > I am not sure if this is necessarily the right way to go for a > library, esp if it can impact backwards compatibility for > bufferevents. As for reducing the size of the library, do you really > think that 30K make a difference these days? > > Niels. It won't impact backwards compatibility unless someone explictly removed support for bufferevents. Additionally, where do we draw the line on what makes a difference these days, when it comes down to it? 1M? 2M? On a typical *bsd/linux platform, I agree, it won't make a significant difference at the end of the day. I also agree that using autoconf and automake to manipulate things is a hack in itself (they always feel like a hack unfortunately). I also don't know how many people are using libevent on smaller platforms (embedded, etc) but I thought that perhaps it could have had some kind of benefit. Part of my impetus was based on this post which directly identifies some concerns and ideas: -- >From provos@citi.umich.edu Thu Feb 8 11:31:50 2007 From: provos@citi.umich.edu (Niels Provos) Date: Thu Feb 8 11:31:53 2007 Subject: [Libevent-users] [Patch] Third attempt: Add support for DNS servers to evdns.c (This time with regression tests!) In-Reply-To: <45BF380D.9030307@nlnetlabs.nl> References: <20070129180804.GY22997@totoro.wangafu.net> <45BF380D.9030307@nlnetlabs.nl> Message-ID: <850f7cbe0702080831v158ffa5of3e54456c5330a75@mail.gmail.com> Status: RO Content-Length: 720 Lines: 16 On 1/30/07, Wouter Wijngaards wrote: > Please, why put these really big http and dns protocols into an event > handling library? I would prefer libevent to stay focused on providing > portable select() and alternatives wrappers. > > The http and evdns are pretty big compared to the rest of libevent. They > can be put in their own library(or -ies) perhaps? Some sort of > libevent-driven application support? There has been some talk about libevent creating two different libraries during compile. One would be the traditional libevent and the other one would layer on top of it. Still thinking about the best way of doing this, but you are not the only one with concerns about bloat. Niels. -- So based on that, I went and wrote a patch. -cl From claris_chen-news at yahoo.com.cn Sat Sep 29 22:38:10 2007 From: claris_chen-news at yahoo.com.cn (claris_chen-news@yahoo.com.cn) Date: Sat Sep 29 22:45:02 2007 Subject: [Libevent-users] [patch]1.3 revision 454 bug in strsep() Message-ID: <677389.33343.qm@web15710.mail.cnb.yahoo.com> 1.3 revision 454 strsep() function has a bug which will cause valid parse with evhttp_parse_request_line while do strcmp to method version and uri. --- http.c (revision 454) +++ http.c (working copy) @@ -147,9 +158,14 @@ tok = *s; d = strstr(tok, del); if (d) + { + *s = '\0';//terminate the string whith NULL. *s = d + strlen(del); + } else + { *s = NULL; + } return tok; } #endif Chen shaowei --------------------------------- 雅虎邮箱,终生伙伴! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://monkeymail.org/archives/libevent-users/attachments/20070930/761052cd/attachment.htm From claris_chen-news at yahoo.com.cn Sat Sep 29 22:52:50 2007 From: claris_chen-news at yahoo.com.cn (claris_chen-news@yahoo.com.cn) Date: Sat Sep 29 22:53:05 2007 Subject: [Libevent-users] [patch] 1.3 revision strsep last i post have a mistake Message-ID: <882104.24061.qm@web15707.mail.cnb.yahoo.com> I am pretty sorry that the last patch I posted is not correct. this one will sovlve it. 1.3 revision 454 strsep() function has a bug which will cause valid parse with evhttp_parse_request_line while do strcmp to method version and uri. --- http.c (revision 454) +++ http.c (working copy) @@ -147,9 +158,14 @@ tok = *s; d = strstr(tok, del); if (d) + { + *d = '\0';//terminate the string whith NULL. *s = d + strlen( del ); + } else + { *s = NULL; + } return tok; } #endif Chen shaowei --------------------------------- @yahoo.cn 新域名、无限量,快来抢注! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://monkeymail.org/archives/libevent-users/attachments/20070930/619b74c1/attachment.htm