summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-10-07 16:20:45 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-10-07 16:20:45 +0200
commitdbf3ab8dfb2cbe8167c464e3cf6a9aa757bfff6a (patch)
treed3d0b18c009757cc5ac7081882152c5f9d9e005b /src/lib/dev.c
parent55d5b9157b78d90d4f6a575d253c58fd50ca531f (diff)
parent192ccde3ae37e33eb33421a6877ed4b4a025fbdb (diff)
downloadouroboros-dbf3ab8dfb2cbe8167c464e3cf6a9aa757bfff6a.tar.gz
ouroboros-dbf3ab8dfb2cbe8167c464e3cf6a9aa757bfff6a.zip
Merged in dstaesse/ouroboros/be-ipcp-read-fd (pull request #258)
lib: Add non-copy reading from fd for IPCPs
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c51
1 files changed, 43 insertions, 8 deletions
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));