Skip to content

Commit

Permalink
ai flags are not always preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Widlund committed Nov 12, 2019
1 parent 5d71b4b commit 221974b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/reactor/reactor_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static reactor_status reactor_net_resolver_handler(reactor_event *event)
fileno = socket(ai->ai_family, SOCK_STREAM | SOCK_NONBLOCK, 0);
reactor_assert_int_not_equal(fileno, -1);

if (ai->ai_flags & AI_PASSIVE)
if (net->options & REACTOR_NET_OPTION_PASSIVE)
{
if (net->options & REACTOR_NET_OPTION_REUSEPORT)
(void) setsockopt(fileno, SOL_SOCKET, SO_REUSEPORT, (int[]){1}, sizeof(int));
Expand Down Expand Up @@ -130,6 +130,7 @@ reactor_status reactor_net_bind(reactor_net *net, char *node, char *service)
if (reactor_fd_active(&net->fd))
return REACTOR_ERROR;

net->options |= REACTOR_NET_OPTION_PASSIVE;
net->resolver_job = reactor_resolver_request(reactor_net_resolver_handler, net, node, service, 0, SOCK_STREAM, AI_PASSIVE);
return net->resolver_job ? REACTOR_OK : REACTOR_ERROR;
}
Expand Down
3 changes: 2 additions & 1 deletion src/reactor/reactor_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ enum reactor_net_events
enum reactor_net_options
{
REACTOR_NET_OPTION_REUSEPORT = 0x01,
REACTOR_NET_OPTION_REUSEADDR = 0x02
REACTOR_NET_OPTION_REUSEADDR = 0x02,
REACTOR_NET_OPTION_PASSIVE = 0x04
};

typedef enum reactor_net_options reactor_net_options;
Expand Down

0 comments on commit 221974b

Please sign in to comment.