From f7ec0e17c36a079394b1950ee56c16cc4f1795c8 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 12 Dec 2014 18:37:54 +0100 Subject: [PATCH] miniupnpc-libevent: split upnpc_init() / upnpc_start() --- miniupnpc-libevent/miniupnpc-libevent.c | 9 ++++++++- miniupnpc-libevent/miniupnpc-libevent.h | 2 ++ miniupnpc-libevent/upnpc-libevent.c | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/miniupnpc-libevent/miniupnpc-libevent.c b/miniupnpc-libevent/miniupnpc-libevent.c index 809cb9b..31634fb 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.c +++ b/miniupnpc-libevent/miniupnpc-libevent.c @@ -606,7 +606,6 @@ int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, { int opt = 1; struct sockaddr_in addr; - struct timeval timeout; if(p == NULL || base == NULL) return UPNPC_ERR_INVALID_ARGS; @@ -654,6 +653,14 @@ int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, close(p->ssdp_socket); return UPNPC_ERR_BIND_FAILED; } + return UPNPC_OK; +} + +int upnpc_start(upnpc_t * p) +{ + struct timeval timeout; + if(p == NULL || p->base == NULL) + return UPNPC_ERR_INVALID_ARGS; /* event on SSDP */ p->ev_ssdp_recv = event_new(p->base, p->ssdp_socket, EV_READ|EV_PERSIST, diff --git a/miniupnpc-libevent/miniupnpc-libevent.h b/miniupnpc-libevent/miniupnpc-libevent.h index f5f716f..505b997 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.h +++ b/miniupnpc-libevent/miniupnpc-libevent.h @@ -81,6 +81,8 @@ struct upnpc { int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, upnpc_callback_fn ready_cb, upnpc_callback_fn soap_cb, void * cb_data); +int upnpc_start(upnpc_t * p); + int upnpc_finalize(upnpc_t * p); int upnpc_get_external_ip_address(upnpc_device_t * p); diff --git a/miniupnpc-libevent/upnpc-libevent.c b/miniupnpc-libevent/upnpc-libevent.c index 039884b..9079a4c 100644 --- a/miniupnpc-libevent/upnpc-libevent.c +++ b/miniupnpc-libevent/upnpc-libevent.c @@ -215,6 +215,10 @@ int main(int argc, char * * argv) fprintf(stderr, "upnpc_init() failed\n"); return 1; } + if(upnpc_start(&upnp) != UPNPC_OK) { + fprintf(stderr, "upnp_start() failed\n"); + return 1; + } event_base_dispatch(base); /* TODO : check return value */ printf("finishing...\n");