io.h
Go to the documentation of this file.
1 #include "sick_scan/sick_scan_base.h" /* Base definitions included in all header files, added by add_sick_scan_base_header.py. Do not edit this line. */
2 /*
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2008, Willow Garage, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Willow Garage, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*****************************************************************************
36 ** Ifdefs
37 *****************************************************************************/
38 #ifndef ROSCPP_IO_H_
39 #define ROSCPP_IO_H_
40 
41 /*****************************************************************************
42 ** Includes
43 *****************************************************************************/
44 
45 #include <string>
46 #include "common.h"
47 
48 #ifdef WIN32
49  #include <winsock2.h> // For struct timeval
50  #include <ws2tcpip.h> // Must be after winsock2.h because MS didn't put proper inclusion guards in their headers.
51  #include <sys/types.h>
52  #include <io.h>
53  #include <fcntl.h>
54  #include <process.h> // for _getpid
55 #else
56  #include <poll.h> // should get cmake to explicitly check for poll.h?
57  #include <sys/poll.h>
58  #include <arpa/inet.h>
59  #include <netdb.h>
60  #include <unistd.h>
61  #include <netdb.h> // getnameinfo in network.cpp
62  #include <netinet/in.h> // sockaddr_in in network.cpp
63  #include <netinet/tcp.h> // TCP_NODELAY in transport/transport_tcp.cpp
64 #endif
65 
66 /*****************************************************************************
67 ** Cross Platform Macros
68 *****************************************************************************/
69 
70 #ifdef WIN32
71  #define getpid _getpid
72  #define ROS_INVALID_SOCKET INVALID_SOCKET
73  #define ROS_SOCKETS_SHUT_RDWR SD_BOTH /* Used by ::shutdown() */
74  #define ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN WSAEWOULDBLOCK
75  #ifndef POLLRDNORM
76  #define POLLRDNORM 0x0100 /* mapped to read fds_set */
77  #endif
78  #ifndef POLLRDBAND
79  #define POLLRDBAND 0x0200 /* mapped to exception fds_set */
80  #endif
81  #ifndef POLLIN
82  #define POLLIN (POLLRDNORM | POLLRDBAND) /* There is data to read. */
83  #endif
84  #ifndef POLLPRI
85  #define POLLPRI 0x0400 /* There is urgent data to read. */
86  #endif
87 
88  #ifndef POLLWRNORM
89  #define POLLWRNORM 0x0010 /* mapped to write fds_set */
90  #endif
91  #ifndef POLLOUT
92  #define POLLOUT (POLLWRNORM) /* Writing now will not block. */
93  #endif
94  #ifndef POLLWRBAND
95  #define POLLWRBAND 0x0020 /* mapped to write fds_set */
96  #endif
97  #ifndef POLLERR
98  #define POLLERR 0x0001 /* Error condition. */
99  #endif
100  #ifndef POLLHUP
101  #define POLLHUP 0x0002 /* Hung up. */
102  #endif
103  #ifndef POLLNVAL
104  #define POLLNVAL 0x0004 /* Invalid polling request. */
105  #endif
106 #else
107  #define ROS_SOCKETS_SHUT_RDWR SHUT_RDWR /* Used by ::shutdown() */
108  #define ROS_INVALID_SOCKET ((int) -1)
109  #define ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN EINPROGRESS
110 #endif
111 
112 /*****************************************************************************
113 ** Namespaces
114 *****************************************************************************/
115 
116 namespace roswrap {
117 
118 /*****************************************************************************
119 ** Cross Platform Types
120 *****************************************************************************/
121 
122 #ifdef WIN32
123  typedef SOCKET socket_fd_t;
124  typedef SOCKET signal_fd_t;
125  /* poll emulation support */
126  typedef struct socket_pollfd {
127  socket_fd_t fd; /* file descriptor */
128  short events; /* requested events */
129  short revents; /* returned events */
130  } socket_pollfd;
131 
132  typedef unsigned long int nfds_t;
133  #ifdef _MSC_VER
134  typedef int pid_t; /* return type for windows' _getpid */
135  #endif
136 #else
137  typedef int socket_fd_t;
138  typedef int signal_fd_t;
139  typedef struct pollfd socket_pollfd;
140 #endif
141 
142 /*****************************************************************************
143 ** Functions
144 *****************************************************************************/
145 
149 ROSCPP_DECL int poll_sockets(socket_pollfd *fds, nfds_t nfds, int timeout);
152 ROSCPP_DECL int create_signal_pair(signal_fd_t signal_pair[2]);
153 
154 /*****************************************************************************
155 ** Inlines - almost direct api replacements, should stay fast.
156 *****************************************************************************/
157 
163 inline void close_signal_pair(signal_fd_t signal_pair[2]) {
164 #ifdef WIN32 // use a socket pair
165  ::closesocket(signal_pair[0]);
166  ::closesocket(signal_pair[1]);
167 #else // use a socket pair on mingw or pipe pair on linux, either way, close works
168  ::close(signal_pair[0]);
169  ::close(signal_pair[1]);
170 #endif
171 }
172 
178 #ifdef _MSC_VER
179  inline int write_signal(const signal_fd_t &signal, const char *buffer, const unsigned int &nbyte) {
180  return ::send(signal, buffer, nbyte, 0);
181 // return write(signal, buffer, nbyte);
182  }
183 #else
184  inline ssize_t write_signal(const signal_fd_t &signal, const void *buffer, const size_t &nbyte) {
185  return write(signal, buffer, nbyte);
186  }
187 #endif
188 
189 
195 #ifdef _MSC_VER
196  inline int read_signal(const signal_fd_t &signal, char *buffer, const unsigned int &nbyte) {
197  return ::recv(signal, buffer, nbyte, 0);
198 // return _read(signal, buffer, nbyte);
199  }
200 #else
201  inline ssize_t read_signal(const signal_fd_t &signal, void *buffer, const size_t &nbyte) {
202  return read(signal, buffer, nbyte);
203  }
204 #endif
205 
206 } // namespace roswrap
207 
208 #endif /* ROSCPP_IO_H_ */
209 
roswrap::socket_pollfd
struct pollfd socket_pollfd
Definition: io.h:141
SOCKET
int SOCKET
Definition: udp_sockets.h:81
roswrap::close_socket
ROSCPP_DECL int close_socket(socket_fd_t &socket)
roswrap::last_socket_error
ROSCPP_DECL int last_socket_error()
roswrap::poll_sockets
ROSCPP_DECL int poll_sockets(socket_pollfd *fds, nfds_t nfds, int timeout)
roswrap::last_socket_error_is_would_block
ROSCPP_DECL bool last_socket_error_is_would_block()
roswrap::set_non_blocking
ROSCPP_DECL int set_non_blocking(socket_fd_t &socket)
ssize_t
#define ssize_t
Definition: unistd.h:41
roswrap::read_signal
ssize_t read_signal(const signal_fd_t &signal, void *buffer, const size_t &nbyte)
Definition: io.h:203
netdb.h
roswrap
Definition: param_modi.cpp:41
roswrap::last_socket_error_string
const ROSCPP_DECL char * last_socket_error_string()
roswrap::create_signal_pair
ROSCPP_DECL int create_signal_pair(signal_fd_t signal_pair[2])
roswrap::signal_fd_t
int signal_fd_t
Definition: io.h:140
roswrap::write_signal
ssize_t write_signal(const signal_fd_t &signal, const void *buffer, const size_t &nbyte)
Definition: io.h:186
common.h
socket_fd_t
int socket_fd_t
unistd.h
colaa::detail::read
T read(const std::string &str)
General template which is unimplemented; implemented specializations follow below.
Definition: colaa.hpp:72
closesocket
#define closesocket
Definition: udp_sockets.h:85
sick_scan_base.h
sick_generic_device_finder.timeout
timeout
Definition: sick_generic_device_finder.py:113
signal_fd_t
int signal_fd_t
ROSCPP_DECL
#define ROSCPP_DECL
Definition: roswrap/src/cfgsimu/sick_scan/ros/common.h:63
socket_pollfd
struct pollfd socket_pollfd
roswrap::socket_fd_t
int socket_fd_t
Definition: io.h:139
roswrap::close_signal_pair
void close_signal_pair(signal_fd_t signal_pair[2])
Definition: io.h:165


sick_scan_xd
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Fri Oct 25 2024 02:47:08