summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-07 16:05:52 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-10-07 16:05:52 +0200
commit192ccde3ae37e33eb33421a6877ed4b4a025fbdb (patch)
treed3d0b18c009757cc5ac7081882152c5f9d9e005b
parent71f10f5efab37f3df3d909d324cff2e098d21c85 (diff)
downloadouroboros-192ccde3ae37e33eb33421a6877ed4b4a025fbdb.tar.gz
ouroboros-192ccde3ae37e33eb33421a6877ed4b4a025fbdb.zip
lib: Add non-copy reading from fd for IPCPs
-rw-r--r--include/ouroboros/ipcp-dev.h7
-rw-r--r--src/ipcpd/shim-eth-llc/main.c2
-rw-r--r--src/ipcpd/shim-udp/main.c2
-rw-r--r--src/lib/dev.c51
4 files changed, 50 insertions, 12 deletions
diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h
index 3c2ff264..9343aeaa 100644
--- a/include/ouroboros/ipcp-dev.h
+++ b/include/ouroboros/ipcp-dev.h
@@ -39,12 +39,15 @@ int ipcp_flow_req_arr(pid_t api,
int ipcp_flow_alloc_reply(int fd,
int response);
-/* returns flow descriptor and du buff */
-int ipcp_flow_read(struct shm_du_buff ** sdb);
+int ipcp_flow_read(int fd,
+ struct shm_du_buff ** sdb);
int ipcp_flow_write(int fd,
struct shm_du_buff * sdb);
void ipcp_flow_del(struct shm_du_buff * sdb);
+/* returns flow descriptor and du buff */
+int ipcp_read_shim(struct shm_du_buff ** sdb);
+
#endif /* OUROBOROS_IPCP_DEV_H */
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index c5e6d74d..130f3945 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -597,7 +597,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
uint8_t dsap;
uint8_t r_addr[MAC_SIZE];
- fd = ipcp_flow_read(&sdb);
+ fd = ipcp_read_shim(&sdb);
if (fd < 0)
continue;
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 8c31e11a..12f6d82e 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -510,7 +510,7 @@ static void * ipcp_udp_sdu_loop(void * o)
int fd;
struct shm_du_buff * sdb;
- fd = ipcp_flow_read(&sdb);
+ fd = ipcp_read_shim(&sdb);
if (fd < 0)
continue;
diff --git a/src/lib/dev.c b/src/lib/dev.c
index d36764ed..e20d23d4 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -1026,24 +1026,39 @@ int ipcp_flow_alloc_reply(int fd, int response)
return ret;
}
-int ipcp_flow_read(struct shm_du_buff ** sdb)
+int ipcp_flow_read(int fd, struct shm_du_buff ** sdb)
{
- int fd;
- struct rb_entry * e;
-
- e = shm_ap_rbuff_read(ai.rb);
+ int idx = -1;
+ int port_id = -1;
pthread_rwlock_rdlock(&ai.data_lock);
pthread_rwlock_rdlock(&ai.flows_lock);
- fd = ai.ports[e->port_id].fd;
+ if ((port_id = ai.flows[fd].port_id) < 0) {
+ pthread_rwlock_unlock(&ai.flows_lock);
+ pthread_rwlock_unlock(&ai.data_lock);
+ return -ENOTALLOC;
+ }
- *sdb = shm_rdrbuff_get(ai.rdrb, e->index);
+ pthread_rwlock_unlock(&ai.flows_lock);
+ pthread_rwlock_unlock(&ai.data_lock);
+
+ idx = shm_ap_rbuff_read_port(ai.rb, port_id);
+ if (idx < 0) {
+ pthread_rwlock_rdlock(&ai.data_lock);
+ pthread_rwlock_rdlock(&ai.flows_lock);
+ return idx;
+ }
+
+ pthread_rwlock_rdlock(&ai.data_lock);
+ pthread_rwlock_rdlock(&ai.flows_lock);
+
+ *sdb = shm_rdrbuff_get(ai.rdrb, idx);
pthread_rwlock_unlock(&ai.flows_lock);
pthread_rwlock_unlock(&ai.data_lock);
- return fd;
+ return 0;
}
int ipcp_flow_write(int fd, struct shm_du_buff * sdb)
@@ -1114,6 +1129,26 @@ int local_flow_write(int fd, struct rb_entry * e)
return 0;
}
+int ipcp_read_shim(struct shm_du_buff ** sdb)
+{
+ int fd;
+ struct rb_entry * e;
+
+ e = shm_ap_rbuff_read(ai.rb);
+
+ pthread_rwlock_rdlock(&ai.data_lock);
+ pthread_rwlock_rdlock(&ai.flows_lock);
+
+ fd = ai.ports[e->port_id].fd;
+
+ *sdb = shm_rdrbuff_get(ai.rdrb, e->index);
+
+ pthread_rwlock_unlock(&ai.flows_lock);
+ pthread_rwlock_unlock(&ai.data_lock);
+
+ return fd;
+}
+
void ipcp_flow_del(struct shm_du_buff * sdb)
{
shm_rdrbuff_remove(ai.rdrb, shm_du_buff_get_idx(sdb));