summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dev.c26
-rw-r--r--src/lib/sockets.c3
2 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 63cf92f7..95fca1ec 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -154,6 +154,26 @@ static int port_id_to_fd(int port_id)
}
#endif
+static void clean_fds()
+{
+ int i;
+ for (i = 0; i < AP_MAX_FLOWS; ++i) {
+ if (flow_alloc_res(i) < 0) {
+ rw_lock_wrlock(&_ap_instance->flows_lock);
+ if (_ap_instance->flows[i].port_id < 0) {
+ rw_lock_unlock(&_ap_instance->flows_lock);
+ continue;
+ }
+
+ bmp_release(_ap_instance->fds, i);
+ _ap_instance->flows[i].port_id = -1;
+ shm_ap_rbuff_close(_ap_instance->flows[i].rb);
+ _ap_instance->flows[i].rb = NULL;
+ rw_lock_unlock(&_ap_instance->flows_lock);
+ }
+ }
+}
+
int ap_reg(char ** difs,
size_t len)
{
@@ -202,6 +222,7 @@ int ap_reg(char ** difs,
rw_lock_wrlock(&_ap_instance->flows_lock);
fd = bmp_allocate(_ap_instance->fds);
+ _ap_instance->flows[fd].port_id = -1;
rw_lock_unlock(&_ap_instance->flows_lock);
rw_lock_unlock(&_ap_instance->data_lock);
@@ -268,6 +289,8 @@ int flow_accept(int fd,
msg.pid = _ap_instance->api->id;
+ clean_fds();
+
rw_lock_unlock(&_ap_instance->data_lock);
recv_msg = send_recv_irm_msg(&msg);
@@ -389,6 +412,8 @@ int flow_alloc(char * dst_name,
msg.pid = _ap_instance->api->id;
msg.ap_name = _ap_instance->api->name;
+ clean_fds();
+
rw_lock_unlock(&_ap_instance->data_lock);
recv_msg = send_recv_irm_msg(&msg);
@@ -402,6 +427,7 @@ int flow_alloc(char * dst_name,
}
rw_lock_rdlock(&_ap_instance->data_lock);
+
rw_lock_wrlock(&_ap_instance->flows_lock);
fd = bmp_allocate(_ap_instance->fds);
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 4f777805..6c51e916 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -50,6 +50,7 @@ int client_socket_open(char * file_name)
(struct sockaddr *) &serv_addr,
sizeof(serv_addr))) {
LOG_ERR("Failed to connect to daemon");
+ close(sockfd);
return -1;
}
@@ -83,11 +84,13 @@ int server_socket_open(char * file_name)
(struct sockaddr *) &serv_addr,
sizeof(serv_addr))) {
LOG_ERR("Failed to bind socket");
+ close(sockfd);
return -1;
}
if (listen(sockfd, 0)) {
LOG_ERR("Failed to listen to socket");
+ close(sockfd);
return -1;
}