miniupnpc-libevent: split upnpc_init() / upnpc_start()

This commit is contained in:
Thomas Bernard 2014-12-12 18:37:54 +01:00
parent 2d89a05982
commit f7ec0e17c3
3 changed files with 14 additions and 1 deletions

View File

@ -606,7 +606,6 @@ int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif,
{ {
int opt = 1; int opt = 1;
struct sockaddr_in addr; struct sockaddr_in addr;
struct timeval timeout;
if(p == NULL || base == NULL) if(p == NULL || base == NULL)
return UPNPC_ERR_INVALID_ARGS; 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); close(p->ssdp_socket);
return UPNPC_ERR_BIND_FAILED; 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 */ /* event on SSDP */
p->ev_ssdp_recv = event_new(p->base, p->ssdp_socket, p->ev_ssdp_recv = event_new(p->base, p->ssdp_socket,
EV_READ|EV_PERSIST, EV_READ|EV_PERSIST,

View File

@ -81,6 +81,8 @@ struct upnpc {
int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif, 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); 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_finalize(upnpc_t * p);
int upnpc_get_external_ip_address(upnpc_device_t * p); int upnpc_get_external_ip_address(upnpc_device_t * p);

View File

@ -215,6 +215,10 @@ int main(int argc, char * * argv)
fprintf(stderr, "upnpc_init() failed\n"); fprintf(stderr, "upnpc_init() failed\n");
return 1; return 1;
} }
if(upnpc_start(&upnp) != UPNPC_OK) {
fprintf(stderr, "upnp_start() failed\n");
return 1;
}
event_base_dispatch(base); /* TODO : check return value */ event_base_dispatch(base); /* TODO : check return value */
printf("finishing...\n"); printf("finishing...\n");