Deal with errors when binding sockets

This commit is contained in:
Jeremy Lakeman 2013-12-19 17:46:54 +10:30
parent 48dce9a575
commit dbb65228e6
2 changed files with 21 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include <assert.h>
#include <inttypes.h>
#include "serval.h"
#include "mdp_client.h"
#include "msp_client.h"
@ -81,12 +82,15 @@ unsigned msp_socket_count()
void msp_debug()
{
time_ms_t now = gettime_ms();
struct msp_sock *p=root;
DEBUGF("Msp sockets;");
while(p){
DEBUGF("State %d, from %s:%d to %s:%d", p->state,
DEBUGF("State %d, from %s:%d to %s:%d, timeout in %"PRId64"ms",
p->state,
alloca_tohex_sid_t(p->header.local.sid), p->header.local.port,
alloca_tohex_sid_t(p->header.remote.sid), p->header.remote.port);
alloca_tohex_sid_t(p->header.remote.sid), p->header.remote.port,
(p->timeout - now));
p=p->_next;
}
}
@ -218,7 +222,8 @@ int msp_listen(struct msp_sock *sock)
return -1;
}
sock->timeout = TIME_NEVER_WILL;
sock->timeout = gettime_ms()+1000;
sock->next_action = sock->timeout;
return 0;
}
@ -560,6 +565,8 @@ static int process_packet(int mdp_sock, struct mdp_header *header, const uint8_t
s->header.flags &= ~MDP_FLAG_BIND;
DEBUGF("Bound to %s:%d", alloca_tohex_sid_t(header->local.sid), header->local.port);
s->next_action = gettime_ms();
if (s->state & MSP_STATE_LISTENING)
s->timeout = TIME_NEVER_WILL;
return 0;
}

View File

@ -189,8 +189,18 @@ static int msp_handler(struct msp_sock *sock, msp_state_t state, const uint8_t *
static int msp_listener(struct msp_sock *sock, msp_state_t state, const uint8_t *payload, size_t len, void *UNUSED(context))
{
if (state & MSP_STATE_CLOSED)
if (state & MSP_STATE_ERROR){
WHY("Error listening for incoming connections");
}
if (state & MSP_STATE_CLOSED){
if (msp_socket_count()==0){
unschedule(&mdp_sock);
if (is_watching(&mdp_sock))
unwatch(&mdp_sock);
}
return 0;
}
struct mdp_sockaddr remote;
msp_get_remote_adr(sock, &remote);