summaryrefslogtreecommitdiff
path: root/src/ipcpd/normal/connmgr.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2018-06-19 11:38:23 +0200
committerDimitri Staessens <[email protected]>2018-06-19 13:55:45 +0200
commita5362f24b4dd48f7203be418c6d66f6edccb8d69 (patch)
treed74819582ddf4e4ccfe629dd1b8d2d96df841aab /src/ipcpd/normal/connmgr.c
parentaea32291530c2dbec84ff424a8c7f224bd1b13d7 (diff)
downloadouroboros-a5362f24b4dd48f7203be418c6d66f6edccb8d69.tar.gz
ouroboros-a5362f24b4dd48f7203be418c6d66f6edccb8d69.zip
ipcpd: Change connection down to flow down
The DT component was flagging a connection as down and passing the fd that was down. Of course the other components expect a connection instead of just a fd. Now the connection manager will listen to flow up and down events, and flag the connection up or down if needed. Signed-off-by: Sander Vrijders <[email protected]> Signed-off-by: Dimitri Staessens <[email protected]>
Diffstat (limited to 'src/ipcpd/normal/connmgr.c')
-rw-r--r--src/ipcpd/normal/connmgr.c57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/ipcpd/normal/connmgr.c b/src/ipcpd/normal/connmgr.c
index 6301baed..9530633b 100644
--- a/src/ipcpd/normal/connmgr.c
+++ b/src/ipcpd/normal/connmgr.c
@@ -54,7 +54,6 @@ struct conn_el {
};
struct comp {
- struct nbs * nbs;
struct conn_info info;
struct list_head conns;
@@ -82,6 +81,29 @@ static int get_id_by_name(const char * name)
return -1;
}
+static int get_conn_by_fd(int fd,
+ enum comp_id id,
+ struct conn * conn)
+{
+ struct list_head * p;
+
+ pthread_mutex_lock(&connmgr.comps[id].lock);
+
+ list_for_each(p, &connmgr.comps[id].conns) {
+ struct conn_el * c =
+ list_entry(p, struct conn_el, next);
+ if (c->conn.flow_info.fd == fd) {
+ *conn = c->conn;
+ pthread_mutex_unlock(&connmgr.comps[id].lock);
+ return 0;
+ }
+ }
+
+ pthread_mutex_unlock(&connmgr.comps[id].lock);
+
+ return -1;
+}
+
static int add_comp_conn(enum comp_id id,
int fd,
qosspec_t qs,
@@ -163,10 +185,39 @@ static void * flow_acceptor(void * o)
return (void *) 0;
}
+static void handle_event(void * self,
+ int event,
+ const void * o)
+{
+ struct conn conn;
+
+ (void) self;
+
+ if (!(event == NOTIFY_DT_FLOW_UP || event == NOTIFY_DT_FLOW_DOWN))
+ return;
+
+ if (get_conn_by_fd(*((int *) o), COMPID_DT, &conn))
+ return;
+
+ switch (event) {
+ case NOTIFY_DT_FLOW_UP:
+ notifier_event(NOTIFY_DT_CONN_UP, &conn);
+ break;
+ case NOTIFY_DT_FLOW_DOWN:
+ notifier_event(NOTIFY_DT_CONN_DOWN, &conn);
+ break;
+ default:
+ break;
+ }
+}
+
int connmgr_init(void)
{
connmgr.state = CONNMGR_INIT;
+ if (notifier_reg(handle_event, NULL))
+ return -1;
+
return 0;
}
@@ -174,6 +225,8 @@ void connmgr_fini(void)
{
int i;
+ notifier_unreg(handle_event);
+
if (connmgr.state == CONNMGR_RUNNING)
pthread_join(connmgr.acceptor, NULL);
@@ -455,7 +508,7 @@ int connmgr_wait(enum comp_id id,
*conn = el->conn;
list_del(&el->next);
- free(el);
+ list_add(&el->next, &connmgr.comps[id].conns);
pthread_mutex_unlock(&comp->lock);