Skip to content

Commit

Permalink
http: fix conflicts EVHTTP_CON_AUTOFREE and EVHTTP_CON_REUSE_CONNECTE…
Browse files Browse the repository at this point in the history
…D_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: libevent#182
  • Loading branch information
azat committed Feb 24, 2016
1 parent 365f181 commit 4dc0979
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
9 changes: 5 additions & 4 deletions http-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ struct evhttp_connection {
ev_uint64_t max_body_size;

int flags;
#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 */
#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 */
/* 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 */
Expand Down
11 changes: 6 additions & 5 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
return 1;
}
int avail_flags = 0;
avail_flags |= EVHTTP_CON_REUSE_CONNECTED_ADDR;

evcon->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 |= flags;

return 0;
}
Expand Down
5 changes: 4 additions & 1 deletion include/event2/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 4dc0979

Please sign in to comment.