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

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     |   17 +++++++++++++++++
 lib/alchemy/pipe.c     |   26 +++++++++++++++++++++-----
 lib/alchemy/pipe.h     |    3 +++
 4 files changed, 44 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..daaa757 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
@@ -80,6 +81,20 @@ static void alchemy_help(void)
         fprintf(stderr, "--alchemy-clock-resolution=<ns>  tick value (default 
1ns, tickless)\n");
 }
 
+#ifdef CONFIG_XENO_COBALT
+
+static inline void init_corespec(void)
+{
+       syncluster_init(&alchemy_pipe_table, "alchemy.pipe");
+       registry_add_dir("/alchemy/pipes");
+}
+
+#else
+
+static inline void init_corespec(void) { }
+
+#endif
+
 static int alchemy_init(void)
 {
        int ret;
@@ -112,6 +127,8 @@ static int alchemy_init(void)
        registry_add_dir("/alchemy/heaps");
        registry_add_dir("/alchemy/alarms");
 
+       init_corespec();
+
        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