summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-12-28 10:57:04 +0100
committerSander Vrijders <[email protected]>2016-12-28 10:57:04 +0100
commit43a3231b03aa0a639bcd8d61784c84095edfdb6e (patch)
tree3e722461be65504e6658f75b7b651f93bb8764e1 /src/lib
parentbd99555a130400cfec1cbdcf5e4eaa08f133d041 (diff)
parentf8e230049143412ac424d4cbfd4ca95b6c7f64e1 (diff)
downloadouroboros-43a3231b03aa0a639bcd8d61784c84095edfdb6e.tar.gz
ouroboros-43a3231b03aa0a639bcd8d61784c84095edfdb6e.zip
Merged in dstaesse/ouroboros/be-qoscube (pull request #329)
Some fixes
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/cdap.c33
-rw-r--r--src/lib/cdap_req.c25
-rw-r--r--src/lib/cdap_req.h3
-rw-r--r--src/lib/dev.c42
-rw-r--r--src/lib/irm.c29
5 files changed, 63 insertions, 69 deletions
diff --git a/src/lib/cdap.c b/src/lib/cdap.c
index 5671c515..17104770 100644
--- a/src/lib/cdap.c
+++ b/src/lib/cdap.c
@@ -105,7 +105,8 @@ static int release_invoke_id(struct cdap * instance, int id)
#define cdap_sent_has_key(i, key) (cdap_sent_get_by_key(i, key) != NULL)
-struct cdap_req * cdap_sent_get_by_key(struct cdap * instance, cdap_key_t key)
+static struct cdap_req * cdap_sent_get_by_key(struct cdap * instance,
+ cdap_key_t key)
{
struct list_head * p = NULL;
struct cdap_req * req = NULL;
@@ -128,13 +129,17 @@ struct cdap_req * cdap_sent_get_by_key(struct cdap * instance, cdap_key_t key)
return NULL;
}
-static int cdap_sent_add(struct cdap * instance, struct cdap_req * req)
+static struct cdap_req * cdap_sent_add(struct cdap * instance, cdap_key_t key)
{
- assert (instance);
- assert (req);
+ struct cdap_req * req;
- if (cdap_sent_has_key(instance, req->key))
- return -EPERM;
+ assert(instance);
+ assert(key >= 0);
+ assert(!cdap_sent_has_key(instance, key));
+
+ req = cdap_req_create(key);
+ if (req == NULL)
+ return NULL;
pthread_rwlock_wrlock(&instance->sent_lock);
@@ -142,7 +147,7 @@ static int cdap_sent_add(struct cdap * instance, struct cdap_req * req)
pthread_rwlock_unlock(&instance->sent_lock);
- return 0;
+ return req;
}
static void cdap_sent_del(struct cdap * instance, struct cdap_req * req)
@@ -157,6 +162,8 @@ static void cdap_sent_del(struct cdap * instance, struct cdap_req * req)
list_del(&req->next);
pthread_rwlock_unlock(&instance->sent_lock);
+
+ cdap_req_destroy(req);
}
static void cdap_sent_destroy(struct cdap * instance)
@@ -249,6 +256,7 @@ static void * sdu_reader(void * o)
free(rcvd);
continue;
}
+
rcvd->iid = msg->invoke_id;
rcvd->flags = msg->flags;
rcvd->name = strdup(msg->name);
@@ -494,18 +502,15 @@ cdap_key_t cdap_request_send(struct cdap * instance,
key = invoke_id_to_key(iid);
- req = cdap_req_create(key);
- if (req == NULL)
- return INVALID_CDAP_KEY;
-
- if (cdap_sent_add(instance, req)) {
- cdap_req_destroy(req);
+ req = cdap_sent_add(instance, key);
+ if (req == NULL) {
+ release_invoke_id(instance, iid);
return INVALID_CDAP_KEY;
}
if (write_msg(instance, &msg)) {
cdap_sent_del(instance, req);
- cdap_req_destroy(req);
+ release_invoke_id(instance, iid);
return INVALID_CDAP_KEY;
}
diff --git a/src/lib/cdap_req.c b/src/lib/cdap_req.c
index f80b10d7..57ad22c5 100644
--- a/src/lib/cdap_req.c
+++ b/src/lib/cdap_req.c
@@ -70,14 +70,14 @@ void cdap_req_destroy(struct cdap_req * creq)
}
if (creq->state == REQ_INIT)
- creq->state = REQ_DONE;
+ creq->state = REQ_NULL;
if (creq->state == REQ_PENDING) {
creq->state = REQ_DESTROY;
pthread_cond_broadcast(&creq->cond);
}
- while (creq->state != REQ_DONE)
+ while (creq->state != REQ_NULL)
pthread_cond_wait(&creq->cond, &creq->lock);
pthread_mutex_unlock(&creq->lock);
@@ -109,17 +109,21 @@ int cdap_req_wait(struct cdap_req * creq)
creq->state = REQ_PENDING;
while (creq->state == REQ_PENDING) {
- if ((ret = -pthread_cond_timedwait(&creq->cond,
- &creq->lock,
- &abstime)) == -ETIMEDOUT)
+ ret = -pthread_cond_timedwait(&creq->cond,
+ &creq->lock,
+ &abstime);
+ if (ret == -ETIMEDOUT)
break;
}
- if (creq->state == REQ_DESTROY)
+ if (creq->state == REQ_DESTROY) {
ret = -1;
-
- creq->state = REQ_DONE;
- pthread_cond_broadcast(&creq->cond);
+ creq->state = REQ_NULL;
+ pthread_cond_broadcast(&creq->cond);
+ } else {
+ creq->state = REQ_DONE;
+ pthread_cond_broadcast(&creq->cond);
+ }
pthread_mutex_unlock(&creq->lock);
@@ -146,5 +150,8 @@ void cdap_req_respond(struct cdap_req * creq, int response, buffer_t data)
while (creq->state == REQ_RESPONSE)
pthread_cond_wait(&creq->cond, &creq->lock);
+ creq->state = REQ_NULL;
+ pthread_cond_broadcast(&creq->cond);
+
pthread_mutex_unlock(&creq->lock);
}
diff --git a/src/lib/cdap_req.h b/src/lib/cdap_req.h
index 9d5cb0c8..b2ded060 100644
--- a/src/lib/cdap_req.h
+++ b/src/lib/cdap_req.h
@@ -31,7 +31,8 @@
#include <pthread.h>
enum creq_state {
- REQ_INIT = 0,
+ REQ_NULL = 0,
+ REQ_INIT,
REQ_PENDING,
REQ_RESPONSE,
REQ_DONE,
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 8eb98506..3a1df16d 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -176,7 +176,7 @@ static int api_announce(char * ap_name)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL) {
- return -1;
+ return -EIRMD;
}
if (!recv_msg->has_result || (ret = recv_msg->result)) {
@@ -359,7 +359,7 @@ int flow_accept(char ** ae_name, qosspec_t * qos)
recv_msg = send_recv_irm_msg_b(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (!recv_msg->has_api || !recv_msg->has_port_id) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -465,7 +465,7 @@ int flow_alloc_resp(int fd, int response)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -476,16 +476,6 @@ int flow_alloc_resp(int fd, int response)
irm_msg__free_unpacked(recv_msg, NULL);
- if (response) {
- pthread_rwlock_rdlock(&ai.data_lock);
- pthread_rwlock_wrlock(&ai.flows_lock);
-
- reset_flow(fd);
-
- pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
- }
-
return ret;
}
@@ -517,7 +507,7 @@ int flow_alloc(char * dst_name, char * src_ae_name, qosspec_t * qos)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (!recv_msg->has_api || !recv_msg->has_port_id) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -603,27 +593,17 @@ int flow_alloc_res(int fd)
recv_msg = send_recv_irm_msg_b(&msg);
if (recv_msg == NULL)
- result = -1;
+ return -EIRMD;
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
- result = -1;
+ return -1;
}
result = recv_msg->result;
irm_msg__free_unpacked(recv_msg, NULL);
- if (result) {
- pthread_rwlock_rdlock(&ai.data_lock);
- pthread_rwlock_wrlock(&ai.flows_lock);
-
- reset_flow(fd);
-
- pthread_rwlock_unlock(&ai.flows_lock);
- pthread_rwlock_unlock(&ai.data_lock);
- }
-
return result;
}
@@ -655,9 +635,9 @@ int flow_dealloc(int fd)
pthread_rwlock_unlock(&ai.flows_lock);
pthread_rwlock_unlock(&ai.data_lock);
- recv_msg = send_recv_irm_msg_b(&msg);
+ recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (!recv_msg->has_result) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -1208,7 +1188,7 @@ int ipcp_create_r(pid_t api)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -1254,7 +1234,7 @@ int ipcp_flow_req_arr(pid_t api, char * dst_name, char * src_ae_name)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (!recv_msg->has_port_id || !recv_msg->has_api) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -1336,7 +1316,7 @@ int ipcp_flow_alloc_reply(int fd, int response)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 4b9a6285..969a78c3 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -47,7 +47,7 @@ pid_t irm_create_ipcp(char * name,
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -75,7 +75,7 @@ int irm_destroy_ipcp(pid_t api)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -147,9 +147,8 @@ int irm_bootstrap_ipcp(pid_t api,
}
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL) {
- return -1;
- }
+ if (recv_msg == NULL)
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -179,7 +178,7 @@ ssize_t irm_list_ipcps(char * name,
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL) {
free(msg.dif_name);
- return -1;
+ return -EIRMD;
}
if (recv_msg->apis == NULL) {
@@ -227,7 +226,7 @@ int irm_enroll_ipcp(pid_t api,
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL) {
free(msg.dif_name);
- return -1;
+ return -EIRMD;
}
if (recv_msg->has_result == false) {
@@ -358,8 +357,11 @@ int irm_bind_ap(char * ap,
msg.opts = opts;
recv_msg = send_recv_irm_msg(&msg);
+
+ free(full_ap_name);
+
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -369,7 +371,6 @@ int irm_bind_ap(char * ap,
ret = recv_msg->result;
irm_msg__free_unpacked(recv_msg, NULL);
- free(full_ap_name);
return ret;
}
@@ -389,7 +390,7 @@ int irm_bind_api(pid_t api, char * name)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -417,7 +418,7 @@ int irm_unbind_ap(char * ap, char * name)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -446,7 +447,7 @@ int irm_unbind_api(pid_t api, char * name)
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -479,7 +480,7 @@ int irm_reg(char * name,
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
@@ -513,7 +514,7 @@ int irm_unreg(char * name,
recv_msg = send_recv_irm_msg(&msg);
if (recv_msg == NULL)
- return -1;
+ return -EIRMD;
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);