http: fix conflicts EVHTTP_CON_AUTOFREE and EVHTTP_CON_REUSE_CONNECTED_ADDR

And we can't make them continuous, since the latest is a public API, and
otherwise we will break binary compatibility.
Also extra check for EVHTTP_CON_PUBLIC_FLAGS_END, in case somebody forgot about
this (implementer I mean).

Refs: #182
This commit is contained in:
Azat Khuzhin 2016-02-15 02:59:40 +03:00
parent 365f181aa3
commit 4dc09795c0
3 changed files with 15 additions and 10 deletions

View File

@ -74,7 +74,8 @@ struct evhttp_connection {
#define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
#define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
#define EVHTTP_CON_CLOSEDETECT 0x0004 /* detecting if persistent close */
#define EVHTTP_CON_AUTOFREE 0x0008 /* set when we want to auto free the connection */
/* set when we want to auto free the connection */
#define EVHTTP_CON_AUTOFREE EVHTTP_CON_PUBLIC_FLAGS_END
struct timeval timeout; /* timeout for events */
int retry_cnt; /* retry count */

11
http.c
View File

@ -2342,13 +2342,14 @@ void evhttp_connection_set_family(struct evhttp_connection *evcon,
int evhttp_connection_set_flags(struct evhttp_connection *evcon,
int flags)
{
if (flags & ~(EVHTTP_CON_REUSE_CONNECTED_ADDR)) {
int avail_flags = 0;
avail_flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR;
if (flags & ~avail_flags || flags > EVHTTP_CON_PUBLIC_FLAGS_END)
return 1;
}
evcon->flags &= ~avail_flags;
evcon->flags &= ~(EVHTTP_CON_REUSE_CONNECTED_ADDR);
evcon->flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR;
evcon->flags |= flags;
return 0;
}

View File

@ -637,7 +637,10 @@ EVENT2_EXPORT_SYMBOL
void evhttp_connection_set_family(struct evhttp_connection *evcon,
int family);
#define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008 /* reuse connection address on retry */
/* reuse connection address on retry */
#define EVHTTP_CON_REUSE_CONNECTED_ADDR 0x0008
/* Padding for public flags, @see EVHTTP_CON_* in http-internal.h */
#define EVHTTP_CON_PUBLIC_FLAGS_END 0x100000
/**
* Set connection flags.
*