Xenomai  3.0.8
rtdm.h
1 /*
2  * Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _XENOMAI_TRANK_RTDM_RTDM_H
19 #define _XENOMAI_TRANK_RTDM_RTDM_H
20 
21 #include_next <rtdm/rtdm.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #ifndef RTDM_NO_DEFAULT_USER_API
28 
29 #define rt_dev_call(__call, __args...) \
30 ({ \
31  int __ret; \
32  __ret = __RT(__call(__args)); \
33  __ret < 0 ? -errno : __ret; \
34 })
35 
36 #define rt_dev_open(__args...) rt_dev_call(open, __args)
37 #define rt_dev_ioctl(__args...) rt_dev_call(ioctl, __args)
38 
39 static inline int rt_dev_socket(int domain, int type, int protocol)
40 {
41  return rt_dev_call(socket, domain, type, protocol);
42 }
43 
44 static inline ssize_t rt_dev_recvmsg(int fd, struct msghdr *msg, int flags)
45 {
46  return rt_dev_call(recvmsg, fd, msg, flags);
47 }
48 
49 static inline ssize_t rt_dev_recv(int fd, void *buf, size_t len, int flags)
50 {
51  return rt_dev_call(recvfrom, fd, buf, len, flags, NULL, NULL);
52 }
53 
54 static inline ssize_t rt_dev_sendmsg(int fd, const struct msghdr *msg, int flags)
55 {
56  return rt_dev_call(sendmsg, fd, msg, flags);
57 }
58 
59 static inline ssize_t rt_dev_sendto(int fd, const void *buf, size_t len,
60  int flags, const struct sockaddr *to,
61  socklen_t tolen)
62 {
63  struct iovec iov;
64  struct msghdr msg;
65 
66  iov.iov_base = (void *)buf;
67  iov.iov_len = len;
68 
69  msg.msg_name = (struct sockaddr *)to;
70  msg.msg_namelen = tolen;
71  msg.msg_iov = &iov;
72  msg.msg_iovlen = 1;
73  msg.msg_control = NULL;
74  msg.msg_controllen = 0;
75 
76  return rt_dev_call(sendmsg, fd, &msg, flags);
77 }
78 
79 static inline ssize_t rt_dev_send(int fd, const void *buf, size_t len,
80  int flags)
81 {
82  return rt_dev_call(sendto, fd, buf, len, flags, NULL, 0);
83 }
84 
85 static inline int rt_dev_getsockopt(int fd, int level, int optname,
86  void *optval, socklen_t *optlen)
87 {
88  struct _rtdm_getsockopt_args args = {
89  level, optname, optval, optlen
90  };
91 
92  return rt_dev_call(ioctl, fd, _RTIOC_GETSOCKOPT, &args);
93 }
94 
95 static inline int rt_dev_setsockopt(int fd, int level, int optname,
96  const void *optval, socklen_t optlen)
97 {
98  struct _rtdm_setsockopt_args args = {
99  level, optname, (void *)optval, optlen
100  };
101 
102  return rt_dev_call(ioctl, fd, _RTIOC_SETSOCKOPT, &args);
103 }
104 
105 static inline int rt_dev_bind(int fd, const struct sockaddr *my_addr,
106  socklen_t addrlen)
107 {
108  struct _rtdm_setsockaddr_args args = { my_addr, addrlen };
109 
110  return rt_dev_call(ioctl, fd, _RTIOC_BIND, &args);
111 }
112 
113 static inline int rt_dev_connect(int fd, const struct sockaddr *serv_addr,
114  socklen_t addrlen)
115 {
116  struct _rtdm_setsockaddr_args args = { serv_addr, addrlen };
117 
118  return rt_dev_call(ioctl, fd, _RTIOC_CONNECT, &args);
119 }
120 
121 static inline int rt_dev_listen(int fd, int backlog)
122 {
123  return rt_dev_call(ioctl, fd, _RTIOC_LISTEN, backlog);
124 }
125 
126 static inline int rt_dev_accept(int fd, struct sockaddr *addr,
127  socklen_t *addrlen)
128 {
129  struct _rtdm_getsockaddr_args args = { addr, addrlen };
130 
131  return rt_dev_call(ioctl, fd, _RTIOC_ACCEPT, &args);
132 }
133 
134 static inline int rt_dev_getsockname(int fd, struct sockaddr *name,
135  socklen_t *namelen)
136 {
137  struct _rtdm_getsockaddr_args args = { name, namelen };
138 
139  return rt_dev_call(ioctl, fd, _RTIOC_GETSOCKNAME, &args);
140 }
141 
142 static inline int rt_dev_getpeername(int fd, struct sockaddr *name,
143  socklen_t *namelen)
144 {
145  struct _rtdm_getsockaddr_args args = { name, namelen };
146 
147  return rt_dev_call(ioctl, fd, _RTIOC_GETPEERNAME, &args);
148 }
149 
150 static inline int rt_dev_shutdown(int fd, int how)
151 {
152  return rt_dev_call(ioctl, fd, _RTIOC_SHUTDOWN, how);
153 }
154 
155 static inline int rt_dev_close(int fd)
156 {
157  return rt_dev_call(close, fd);
158 }
159 
160 static inline ssize_t rt_dev_write(int fd, const void *buf, size_t len)
161 {
162  return rt_dev_call(write, fd, buf, len);
163 }
164 
165 static inline ssize_t rt_dev_read(int fd, void *buf, size_t len)
166 {
167  return rt_dev_call(read, fd, buf, len);
168 }
169 
170 #endif /* !RTDM_NO_DEFAULT_USER_API */
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 
176 #endif /* _XENOMAI_TRANK_RTDM_RTDM_H */