Module: xenomai-rpm
Branch: queue/rtipc
Commit: 579cb5774b28bdb4678117d88432d4597ceff833
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=579cb5774b28bdb4678117d88432d4597ceff833

Author: Philippe Gerum <r...@xenomai.org>
Date:   Sun May 30 15:04:28 2010 +0200

rtipc: encapsulate label option string

---

 examples/rtdm/profiles/ipc/bufp-label.c |   12 ++++++------
 examples/rtdm/profiles/ipc/iddp-label.c |   12 ++++++------
 examples/rtdm/profiles/ipc/xddp-label.c |   12 ++++++------
 include/rtdm/rtipc.h                    |    7 ++++---
 ksrc/drivers/ipc/bufp.c                 |   22 +++++++++++-----------
 ksrc/drivers/ipc/iddp.c                 |   22 +++++++++++-----------
 ksrc/drivers/ipc/xddp.c                 |   22 +++++++++++-----------
 7 files changed, 55 insertions(+), 54 deletions(-)

diff --git a/examples/rtdm/profiles/ipc/bufp-label.c 
b/examples/rtdm/profiles/ipc/bufp-label.c
index 5df0999..5fb9364 100644
--- a/examples/rtdm/profiles/ipc/bufp-label.c
+++ b/examples/rtdm/profiles/ipc/bufp-label.c
@@ -50,7 +50,7 @@ static void fail(const char *reason)
 
 void *server(void *arg)
 {
-       char label[BUFP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct sockaddr_ipc saddr;
        char buf[128];
        size_t bufsz;
@@ -75,9 +75,9 @@ void *server(void *arg)
         * Set a port label. This name will be registered when
         * binding, in addition to the port number (if given).
         */
-       strcpy(label, BUFP_PORT_LABEL);
+       strcpy(plabel.label, BUFP_PORT_LABEL);
        ret = setsockopt(s, SOL_BUFP, BUFP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
 
@@ -112,8 +112,8 @@ void *server(void *arg)
 
 void *client(void *arg)
 {
+       struct rtipc_port_label plabel;
        struct sockaddr_ipc svsaddr;
-       char label[BUFP_LABEL_LEN];
        int ret, s, n = 0, len;
        struct timespec ts;
        char buf[128];
@@ -129,9 +129,9 @@ void *client(void *arg)
         * BUFP does not try to register this label for the client
         * port as well (like the server thread did).
         */
-       strcpy(label, BUFP_PORT_LABEL);
+       strcpy(plabel.label, BUFP_PORT_LABEL);
        ret = setsockopt(s, SOL_BUFP, BUFP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
 
diff --git a/examples/rtdm/profiles/ipc/iddp-label.c 
b/examples/rtdm/profiles/ipc/iddp-label.c
index 1ad324f..1a52328 100644
--- a/examples/rtdm/profiles/ipc/iddp-label.c
+++ b/examples/rtdm/profiles/ipc/iddp-label.c
@@ -60,7 +60,7 @@ static void fail(const char *reason)
 void *server(void *arg)
 {
        struct sockaddr_ipc saddr, claddr;
-       char label[IDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        socklen_t addrlen;
        char buf[128];
        int ret, s;
@@ -78,9 +78,9 @@ void *server(void *arg)
         * Set a port label. This name will be registered when
         * binding, in addition to the port number (if given).
         */
-       strcpy(label, IDDP_PORT_LABEL);
+       strcpy(plabel.label, IDDP_PORT_LABEL);
        ret = setsockopt(s, SOL_IDDP, IDDP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
 
@@ -118,7 +118,7 @@ void *server(void *arg)
 void *client(void *arg)
 {
        struct sockaddr_ipc svsaddr, clsaddr;
-       char label[IDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        int ret, s, n = 0, len;
        struct timespec ts;
        char buf[128];
@@ -145,9 +145,9 @@ void *client(void *arg)
         * IDDP does not try to register this label for the client
         * port as well (like the server thread did).
         */
-       strcpy(label, IDDP_PORT_LABEL);
+       strcpy(plabel.label, IDDP_PORT_LABEL);
        ret = setsockopt(s, SOL_IDDP, IDDP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
 
diff --git a/examples/rtdm/profiles/ipc/xddp-label.c 
b/examples/rtdm/profiles/ipc/xddp-label.c
index afd6ad9..0bc040f 100644
--- a/examples/rtdm/profiles/ipc/xddp-label.c
+++ b/examples/rtdm/profiles/ipc/xddp-label.c
@@ -95,7 +95,7 @@ static void fail(const char *reason)
 
 void *realtime_thread1(void *arg)
 {
-       char label[XDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct sockaddr_ipc saddr;
        int ret, s, len;
        char buf[128];
@@ -115,9 +115,9 @@ void *realtime_thread1(void *arg)
         * Set a port label. This name will be registered when
         * binding, in addition to the port number (if given).
         */
-       strcpy(label, XDDP_PORT_LABEL);
+       strcpy(plabel.label, XDDP_PORT_LABEL);
        ret = setsockopt(s, SOL_XDDP, XDDP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
        /*
@@ -153,7 +153,7 @@ void *realtime_thread1(void *arg)
 
 void *realtime_thread2(void *arg)
 {
-       char label[XDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct sockaddr_ipc saddr;
        int ret, s, n = 0, len;
        struct timespec ts;
@@ -185,9 +185,9 @@ void *realtime_thread2(void *arg)
         * Set a port label. This name will be used to find the peer
         * when connecting, instead of the port number.
         */
-       strcpy(label, XDDP_PORT_LABEL);
+       strcpy(plabel.label, XDDP_PORT_LABEL);
        ret = setsockopt(s, SOL_XDDP, XDDP_LABEL,
-                        label, sizeof(label));
+                        &plabel, sizeof(plabel));
        if (ret)
                fail("setsockopt");
 
diff --git a/include/rtdm/rtipc.h b/include/rtdm/rtipc.h
index 0e7f2cd..3d2e376 100644
--- a/include/rtdm/rtipc.h
+++ b/include/rtdm/rtipc.h
@@ -80,6 +80,10 @@ enum {
   */
 typedef int16_t rtipc_port_t;
 
+struct rtipc_port_label {
+       char label[XNOBJECT_NAME_LEN];
+};
+
 struct sockaddr_ipc {
        sa_family_t sipc_family; /* AF_RTIPC */
        rtipc_port_t sipc_port;
@@ -91,17 +95,14 @@ struct sockaddr_ipc {
 #define XDDP_POOLSZ            2
 #define XDDP_BUFSZ             3
 #define XDDP_MONITOR           4
-#define XDDP_LABEL_LEN         XNOBJECT_NAME_LEN
 
 #define SOL_IDDP               312
 #define IDDP_LABEL             1
 #define IDDP_POOLSZ            2
-#define IDDP_LABEL_LEN         XNOBJECT_NAME_LEN
 
 #define SOL_BUFP               313
 #define BUFP_LABEL             1
 #define BUFP_BUFSZ             2
-#define BUFP_LABEL_LEN         XNOBJECT_NAME_LEN
 
 /* XDDP in-kernel monitored events */
 #define XDDP_EVTIN     1
diff --git a/ksrc/drivers/ipc/bufp.c b/ksrc/drivers/ipc/bufp.c
index 39e0213..9078539 100644
--- a/ksrc/drivers/ipc/bufp.c
+++ b/ksrc/drivers/ipc/bufp.c
@@ -41,7 +41,7 @@ struct bufp_socket {
        size_t bufsz;
        u_long status;
        xnhandle_t handle;
-       char label[BUFP_LABEL_LEN];
+       char label[XNOBJECT_NAME_LEN];
 
        off_t rdoff;
        off_t wroff;
@@ -809,7 +809,7 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
                             void *arg)
 {
        struct _rtdm_setsockopt_args sopt;
-       char label[BUFP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct timeval tv;
        int ret = 0;
        size_t len;
@@ -872,10 +872,10 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
                break;
 
        case BUFP_LABEL:
-               if (sopt.optlen < sizeof(label))
+               if (sopt.optlen < sizeof(plabel))
                        return -EINVAL;
-               if (rtipc_get_arg(user_info, label,
-                                 sopt.optval, sizeof(label) - 1))
+               if (rtipc_get_arg(user_info, &plabel,
+                                 sopt.optval, sizeof(plabel)))
                        return -EFAULT;
                RTDM_EXECUTE_ATOMICALLY(
                        /*
@@ -885,8 +885,8 @@ static int __bufp_setsockopt(struct bufp_socket *sk,
                        if (test_bit(_BUFP_BINDING, &sk->status))
                                ret = -EALREADY;
                        else {
-                               strcpy(sk->label, label);
-                               sk->label[BUFP_LABEL_LEN-1] = 0;
+                               strcpy(sk->label, plabel.label);
+                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
                        }
                );
                break;
@@ -903,7 +903,7 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
                             void *arg)
 {
        struct _rtdm_getsockopt_args sopt;
-       char label[BUFP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct timeval tv;
        socklen_t len;
        int ret = 0;
@@ -948,13 +948,13 @@ static int __bufp_getsockopt(struct bufp_socket *sk,
        switch (sopt.optname) {
 
        case BUFP_LABEL:
-               if (len < sizeof(label))
+               if (len < sizeof(plabel))
                        return -EINVAL;
                RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(label, sk->label);
+                       strcpy(plabel.label, sk->label);
                );
                if (rtipc_put_arg(user_info, sopt.optval,
-                                 label, sizeof(label)))
+                                 &plabel, sizeof(plabel)))
                        return -EFAULT;
                break;
 
diff --git a/ksrc/drivers/ipc/iddp.c b/ksrc/drivers/ipc/iddp.c
index cbd6884..c0ee42d 100644
--- a/ksrc/drivers/ipc/iddp.c
+++ b/ksrc/drivers/ipc/iddp.c
@@ -56,7 +56,7 @@ struct iddp_socket {
        struct list_head inq;
        u_long status;
        xnhandle_t handle;
-       char label[IDDP_LABEL_LEN];
+       char label[XNOBJECT_NAME_LEN];
 
        nanosecs_rel_t rx_timeout;
        nanosecs_rel_t tx_timeout;
@@ -672,7 +672,7 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
                             void *arg)
 {
        struct _rtdm_setsockopt_args sopt;
-       char label[IDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct timeval tv;
        int ret = 0;
        size_t len;
@@ -735,10 +735,10 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
                break;
 
        case IDDP_LABEL:
-               if (sopt.optlen < sizeof(label))
+               if (sopt.optlen < sizeof(plabel))
                        return -EINVAL;
-               if (rtipc_get_arg(user_info, label,
-                                 sopt.optval, sizeof(label) - 1))
+               if (rtipc_get_arg(user_info, &plabel,
+                                 sopt.optval, sizeof(plabel)))
                        return -EFAULT;
                RTDM_EXECUTE_ATOMICALLY(
                        /*
@@ -748,8 +748,8 @@ static int __iddp_setsockopt(struct iddp_socket *sk,
                        if (test_bit(_IDDP_BINDING, &sk->status))
                                ret = -EALREADY;
                        else {
-                               strcpy(sk->label, label);
-                               sk->label[IDDP_LABEL_LEN-1] = 0;
+                               strcpy(sk->label, plabel.label);
+                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
                        }
                );
                break;
@@ -766,7 +766,7 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
                             void *arg)
 {
        struct _rtdm_getsockopt_args sopt;
-       char label[IDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct timeval tv;
        socklen_t len;
        int ret = 0;
@@ -811,13 +811,13 @@ static int __iddp_getsockopt(struct iddp_socket *sk,
        switch (sopt.optname) {
 
        case IDDP_LABEL:
-               if (len < sizeof(label))
+               if (len < sizeof(plabel))
                        return -EINVAL;
                RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(label, sk->label);
+                       strcpy(plabel.label, sk->label);
                );
                if (rtipc_put_arg(user_info, sopt.optval,
-                                 label, sizeof(label)))
+                                 &plabel, sizeof(plabel)))
                        return -EFAULT;
                break;
 
diff --git a/ksrc/drivers/ipc/xddp.c b/ksrc/drivers/ipc/xddp.c
index c88cfcd..37bc6d0 100644
--- a/ksrc/drivers/ipc/xddp.c
+++ b/ksrc/drivers/ipc/xddp.c
@@ -41,7 +41,7 @@ struct xddp_socket {
        int minor;
        size_t poolsz;
        xnhandle_t handle;
-       char label[XDDP_LABEL_LEN];
+       char label[XNOBJECT_NAME_LEN];
 
        struct xddp_message *buffer;
        int buffer_port;
@@ -845,7 +845,7 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
 {
        int (*monitor)(int s, int event, long arg);
        struct _rtdm_setsockopt_args sopt;
-       char label[XDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        rtdm_lockctx_t lockctx;
        struct timeval tv;
        int ret = 0;
@@ -930,18 +930,18 @@ static int __xddp_setsockopt(struct xddp_socket *sk,
                break;
 
        case XDDP_LABEL:
-               if (sopt.optlen < sizeof(label))
+               if (sopt.optlen < sizeof(plabel))
                        return -EINVAL;
-               if (rtipc_get_arg(user_info, label,
-                                 sopt.optval, sizeof(label) - 1))
+               if (rtipc_get_arg(user_info, &plabel,
+                                 sopt.optval, sizeof(plabel)))
                        return -EFAULT;
                RTDM_EXECUTE_ATOMICALLY(
                        if (test_bit(_XDDP_BOUND, &sk->status) ||
                            test_bit(_XDDP_BINDING, &sk->status))
                                ret = -EALREADY;
                        else {
-                               strcpy(sk->label, label);
-                               sk->label[XDDP_LABEL_LEN-1] = 0;
+                               strcpy(sk->label, plabel.label);
+                               sk->label[XNOBJECT_NAME_LEN-1] = 0;
                        }
                );
                break;
@@ -958,7 +958,7 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
                             void *arg)
 {
        struct _rtdm_getsockopt_args sopt;
-       char label[XDDP_LABEL_LEN];
+       struct rtipc_port_label plabel;
        struct timeval tv;
        socklen_t len;
        int ret = 0;
@@ -994,13 +994,13 @@ static int __xddp_getsockopt(struct xddp_socket *sk,
        switch (sopt.optname) {
 
        case XDDP_LABEL:
-               if (len < sizeof(label))
+               if (len < sizeof(plabel))
                        return -EINVAL;
                RTDM_EXECUTE_ATOMICALLY(
-                       strcpy(label, sk->label);
+                       strcpy(plabel.label, sk->label);
                );
                if (rtipc_put_arg(user_info, sopt.optval,
-                                 label, sizeof(label)))
+                                 &plabel, sizeof(plabel)))
                        return -EFAULT;
                break;
 


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to