summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-udp
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-06-28 10:38:37 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-06-28 10:38:37 +0200
commitacd29da104d0d8ddace2b2693314542bb5a56fcc (patch)
tree5ee8e70778673899a30b587e49ac2080e05e1a03 /src/ipcpd/shim-udp
parent547320513add75e9aad7fb46a90b8975ccd7fcc5 (diff)
parente9e4c6edab303bd725a4904c78ac3f853f8703ae (diff)
downloadouroboros-acd29da104d0d8ddace2b2693314542bb5a56fcc.tar.gz
ouroboros-acd29da104d0d8ddace2b2693314542bb5a56fcc.zip
Merged in dstaesse/ouroboros/be-udp-dealloc (pull request #143)
Be udp dealloc
Diffstat (limited to 'src/ipcpd/shim-udp')
-rw-r--r--src/ipcpd/shim-udp/main.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index c465cb32..221e60d2 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -600,7 +600,7 @@ static int ipcp_udp_flow_dealloc_req(int udp_port)
struct shm_ap_rbuff * rb;
pthread_rwlock_rdlock(&_ipcp->state_lock);
- pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
fd = udp_port_to_fd(udp_port);
if (fd < 0) {
@@ -613,6 +613,9 @@ static int ipcp_udp_flow_dealloc_req(int udp_port)
clr_fd(fd);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+
_ap_instance->flows[fd].state = FLOW_NULL;
port_id = _ap_instance->flows[fd].port_id;
_ap_instance->flows[fd].port_id = -1;
@@ -1319,12 +1322,6 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
return -1;
}
- pthread_rwlock_rdlock(&_ap_instance->flows_lock);
-
- set_fd(fd);
-
- pthread_rwlock_unlock(&_ap_instance->flows_lock);
-
pthread_rwlock_wrlock(&_ap_instance->flows_lock);
_ap_instance->flows[fd].port_id = port_id;
@@ -1332,6 +1329,12 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
_ap_instance->flows[fd].rb = rb;
pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
+
+ set_fd(fd);
+
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+
pthread_rwlock_unlock(&_ipcp->state_lock);
if (ipcp_udp_port_alloc(ip_addr,
@@ -1339,10 +1342,13 @@ static int ipcp_udp_flow_alloc(pid_t n_pid,
dst_name,
src_ae_name) < 0) {
pthread_rwlock_rdlock(&_ipcp->state_lock);
- pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
clr_fd(fd);
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+
_ap_instance->flows[fd].port_id = -1;
_ap_instance->flows[fd].state = FLOW_NULL;
shm_ap_rbuff_close(_ap_instance->flows[fd].rb);
@@ -1436,14 +1442,17 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid,
r_saddr.sin_port,
response) < 0) {
pthread_rwlock_rdlock(&_ipcp->state_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
+
+ clr_fd(fd);
+
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
pthread_rwlock_wrlock(&_ap_instance->flows_lock);
_ap_instance->flows[fd].state = FLOW_NULL;
shm_ap_rbuff_close(_ap_instance->flows[fd].rb);
_ap_instance->flows[fd].rb = NULL;
- clr_fd(fd);
-
pthread_rwlock_unlock(&_ap_instance->flows_lock);
pthread_rwlock_unlock(&_ipcp->state_lock);
@@ -1464,7 +1473,7 @@ static int ipcp_udp_flow_dealloc(int port_id)
socklen_t r_saddr_len = sizeof(r_saddr);
pthread_rwlock_rdlock(&_ipcp->state_lock);
- pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+ pthread_rwlock_rdlock(&_ap_instance->flows_lock);
fd = port_id_to_fd(port_id);
if (fd < 0) {
@@ -1474,13 +1483,16 @@ static int ipcp_udp_flow_dealloc(int port_id)
return 0;
}
+ clr_fd(fd);
+
+ pthread_rwlock_unlock(&_ap_instance->flows_lock);
+ pthread_rwlock_wrlock(&_ap_instance->flows_lock);
+
_ap_instance->flows[fd].state = FLOW_NULL;
_ap_instance->flows[fd].port_id = -1;
rb = _ap_instance->flows[fd].rb;
_ap_instance->flows[fd].rb = NULL;
- clr_fd(fd);
-
pthread_rwlock_unlock(&_ap_instance->flows_lock);
if (rb != NULL)