diff --git a/ChangeLog b/ChangeLog index f65ecf39..ecd3bcd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -141,7 +141,8 @@ Changes in current version: o New evthread_use_windows_threads() and evthread_use_pthreads() functions to set up the evthread callbacks with reasonable defaults. o Change the semantics of timeouts in conjunction with EV_PERSIST; timeouts in that case will now repeat until deleted. o sendfile, mmap and memory reference support for evbuffers. - + o New evutil_make_listen_socket_reuseable() to abstract SO_REUSEADDR. + Changes in 1.4.0: o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr. o demote most http warnings to debug messages diff --git a/evutil.c b/evutil.c index 8c8e506c..9c2e9530 100644 --- a/evutil.c +++ b/evutil.c @@ -189,6 +189,21 @@ evutil_make_socket_nonblocking(evutil_socket_t fd) return 0; } +int +evutil_make_listen_socket_reuseable(evutil_socket_t sock) +{ +#ifndef WIN32 + int one = 1; + /* REUSEADDR on Unix means, "don't hang on to this address after the + * listener is closed." On Windows, thoug, it means "don't keep other + * processes from binding to this address while we're using it. */ + return setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void*) &one, + (socklen_t)sizeof(one)); +#else + return 0; +#endif +} + ev_int64_t evutil_strtoll(const char *s, char **endptr, int base) { diff --git a/include/event2/util.h b/include/event2/util.h index f22b9339..6d331951 100644 --- a/include/event2/util.h +++ b/include/event2/util.h @@ -121,6 +121,16 @@ int evutil_socketpair(int d, int type, int protocol, evutil_socket_t sv[2]); @return 0 on success, -1 on failure */ int evutil_make_socket_nonblocking(evutil_socket_t sock); + +/** Do platform-specific operations on a listener socket to make sure that + another program will be able to bind this address right after we've + closed the listener + + @param sock The socket to make reuseabla + @return 0 on success, -1 on failure + */ +int evutil_make_listen_socket_reuseable(evutil_socket_t); + #ifdef WIN32 /** Do the platform-specific call needed to close a socket returned from socket() or accept(). */