Module: xenomai-3
Branch: next
Commit: cc94f0c32ceae8a2b539923b56410d18afcb69d2
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cc94f0c32ceae8a2b539923b56410d18afcb69d2

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Oct 30 12:13:05 2014 +0100

alchemy/pipe: fix assorted issues in rt_pipe_create() wrapper to XDDP

In addition, the assigned minor is now returned (for use with
P_MINOR_AUTO).

---

 include/alchemy/pipe.h |    5 +++--
 lib/alchemy/init.c     |    3 +++
 lib/alchemy/pipe.c     |   26 +++++++++++++++++++++-----
 lib/alchemy/pipe.h     |    3 +++
 4 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/include/alchemy/pipe.h b/include/alchemy/pipe.h
index 4be8f85..4f91281 100644
--- a/include/alchemy/pipe.h
+++ b/include/alchemy/pipe.h
@@ -19,6 +19,7 @@
 #define _XENOMAI_ALCHEMY_PIPE_H
 
 #include <stdint.h>
+#include <cobalt/uapi/kernel/pipe.h>
 #include <alchemy/timer.h>
 
 /**
@@ -30,8 +31,8 @@
 #define P_MINOR_AUTO   XNPIPE_MINOR_AUTO
 
 /** Operation flags. */
-#define P_URGENT  0x1
-#define P_NORMAL  0x0
+#define P_URGENT       XNPIPE_URGENT
+#define P_NORMAL       XNPIPE_NORMAL
 
 struct RT_PIPE {
        uintptr_t handle;
diff --git a/lib/alchemy/init.c b/lib/alchemy/init.c
index bf37840..c4fb5ff 100644
--- a/lib/alchemy/init.c
+++ b/lib/alchemy/init.c
@@ -33,6 +33,7 @@
 #include "buffer.h"
 #include "heap.h"
 #include "alarm.h"
+#include "pipe.h"
 
 /**
  * @defgroup alchemy Alchemy API
@@ -92,6 +93,7 @@ static int alchemy_init(void)
        syncluster_init(&alchemy_queue_table, "alchemy.queue");
        syncluster_init(&alchemy_buffer_table, "alchemy.buffer");
        syncluster_init(&alchemy_heap_table, "alchemy.heap");
+       syncluster_init(&alchemy_pipe_table, "alchemy.pipe");
        pvcluster_init(&alchemy_alarm_table, "alchemy.alarm");
 
        ret = clockobj_init(&alchemy_clock, "alchemy", clock_resolution);
@@ -111,6 +113,7 @@ static int alchemy_init(void)
        registry_add_dir("/alchemy/buffers");
        registry_add_dir("/alchemy/heaps");
        registry_add_dir("/alchemy/alarms");
+       registry_add_dir("/alchemy/pipes");
 
        return 0;
 }
diff --git a/lib/alchemy/pipe.c b/lib/alchemy/pipe.c
index 439a00f..be974c0 100644
--- a/lib/alchemy/pipe.c
+++ b/lib/alchemy/pipe.c
@@ -110,7 +110,8 @@ DEFINE_LOOKUP_PRIVATE(pipe, RT_PIPE);
  * pipe. Passing 0 means that all message allocations for this pipe are
  * performed on the Cobalt core heap.
  *
- * @return Zero is returned upon success. Otherwise:
+ * @return The @a minor number assigned to the connection is returned
+ * upon success. Otherwise:
  *
  * - -ENOMEM is returned if the system fails to get memory from the
  * main heap in order to create the pipe.
@@ -136,6 +137,7 @@ int rt_pipe_create(RT_PIPE *pipe,
        struct alchemy_pipe *pcb;
        struct service svc;
        size_t streambufsz;
+       socklen_t addrlen;
        int ret, sock;
 
        if (threadobj_irq_p())
@@ -166,15 +168,15 @@ int rt_pipe_create(RT_PIPE *pipe,
        }
 
        if (poolsize > 0) {
-               ret = __RT(setsockopt(pcb->sock, SOL_XDDP, XDDP_POOLSZ,
+               ret = __RT(setsockopt(sock, SOL_XDDP, XDDP_POOLSZ,
                                      &poolsize, sizeof(poolsize)));
                if (ret)
                        goto fail_sockopt;
        }
 
        streambufsz = ALCHEMY_PIPE_STREAMSZ;
-       ret = __RT(setsockopt(pcb->sock, SOL_XDDP, XDDP_BUFSZ,
-                             &streambufsz, streambufsz));
+       ret = __RT(setsockopt(sock, SOL_XDDP, XDDP_BUFSZ,
+                             &streambufsz, sizeof(streambufsz)));
        if (ret)
                goto fail_sockopt;
 
@@ -185,8 +187,22 @@ int rt_pipe_create(RT_PIPE *pipe,
        if (ret)
                goto fail_sockopt;
 
+       if (minor == P_MINOR_AUTO) {
+               /* Fetch the assigned minor device. */
+               addrlen = sizeof(saddr);
+               ret = __RT(getsockname(sock, (struct sockaddr *)&saddr, 
&addrlen));
+               if (ret)
+                       goto fail_sockopt;
+               if (addrlen != sizeof(saddr)) {
+                       ret = -EINVAL;
+                       goto fail_register;
+               }
+               minor = saddr.sipc_port;
+       }
+
        generate_name(pcb->name, name, &pipe_namegen);
        pcb->sock = sock;
+       pcb->minor = minor;
        pcb->magic = pipe_magic;
 
        if (syncluster_addobj(&alchemy_pipe_table, pcb->name, &pcb->cobj)) {
@@ -198,7 +214,7 @@ int rt_pipe_create(RT_PIPE *pipe,
 
        CANCEL_RESTORE(svc);
 
-       return 0;
+       return minor;
 fail_sockopt:
        ret = -errno;
        if (ret == -EADDRINUSE)
diff --git a/lib/alchemy/pipe.h b/lib/alchemy/pipe.h
index 5d90d75..48843af 100644
--- a/lib/alchemy/pipe.h
+++ b/lib/alchemy/pipe.h
@@ -29,9 +29,12 @@ struct alchemy_pipe {
        unsigned int magic;     /* Must be first. */
        char name[XNOBJECT_NAME_LEN];
        int sock;
+       int minor;
        struct clusterobj cobj;
 };
 
 #define pipe_magic     0x8b8bebeb
 
+extern struct syncluster alchemy_pipe_table;
+
 #endif /* _ALCHEMY_PIPE_H */


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to