diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-31 18:35:17 +0100 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-10-31 18:43:04 +0100 |
commit | 86b6d0ca1b871e629a95c9cf0ddceeeb7e1bd345 (patch) | |
tree | 02f048b2b148ad9426194967cbc332a93742ac52 /src/ipcpd/local | |
parent | add7d5f1e59c661b431ba86ba80d62badc14e762 (diff) | |
download | ouroboros-86b6d0ca1b871e629a95c9cf0ddceeeb7e1bd345.tar.gz ouroboros-86b6d0ca1b871e629a95c9cf0ddceeeb7e1bd345.zip |
lib, ipcpd: Improve flow allocation
All calls for opening rbuffs are now concentrated on the dev side.
This allows some simplifications in the np1 calls. The ipcp_fini call
will not destroy the mutex associated with the state, since the final
state needs to be checked before shutting down an IPCP.
Diffstat (limited to 'src/ipcpd/local')
-rw-r--r-- | src/ipcpd/local/main.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index f95eeae4..f0c85084 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -88,14 +88,10 @@ static void * ipcp_local_sdu_loop(void * o) (void) o; - while (true) { + while (flow_event_wait(local_data.flows, local_data.fq, &timeout)) { int fd; ssize_t idx; - if (flow_event_wait(local_data.flows, local_data.fq, &timeout) - == -ETIMEDOUT) - continue; - pthread_rwlock_rdlock(&ipcpi.state_lock); if (ipcp_get_state() != IPCP_ENROLLED) { @@ -233,7 +229,8 @@ static int ipcp_local_flow_alloc(int fd, LOG_DBG("Allocating flow to %s on fd %d.", dst_name, fd); - assert(dst_name || src_ae_name); + assert(dst_name); + assert(src_ae_name); pthread_rwlock_rdlock(&ipcpi.state_lock); @@ -298,17 +295,24 @@ static int ipcp_local_flow_dealloc(int fd) ipcp_flow_fini(fd); pthread_rwlock_rdlock(&ipcpi.state_lock); + + if (ipcp_get_state() != IPCP_ENROLLED) { + pthread_rwlock_unlock(&ipcpi.state_lock); + LOG_DBG("Won't register with non-enrolled IPCP."); + return -1; /* -ENOTENROLLED */ + } + pthread_rwlock_wrlock(&local_data.lock); flow_set_del(local_data.flows, fd); local_data.in_out[fd] = -1; + flow_dealloc(fd); + pthread_rwlock_unlock(&local_data.lock); pthread_rwlock_unlock(&ipcpi.state_lock); - flow_dealloc(fd); - LOG_INFO("Flow with fd %d deallocated.", fd); return 0; |