Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef ROSCPP_IO_H_
00038 #define ROSCPP_IO_H_
00039
00040
00041
00042
00043
00044 #include <string>
00045 #include "common.h"
00046
00047 #ifdef WIN32
00048 #include <winsock2.h>
00049 #include <ws2tcpip.h>
00050 #include <sys/types.h>
00051 #include <io.h>
00052 #include <fcntl.h>
00053 #include <process.h>
00054 #else
00055 #include <poll.h>
00056 #include <sys/poll.h>
00057 #include <arpa/inet.h>
00058 #include <netdb.h>
00059 #include <unistd.h>
00060 #include <netdb.h>
00061 #include <netinet/in.h>
00062 #include <netinet/tcp.h>
00063 #endif
00064
00065
00066
00067
00068
00069 #ifdef WIN32
00070 #define getpid _getpid
00071 #define ROS_INVALID_SOCKET INVALID_SOCKET
00072 #define ROS_SOCKETS_SHUT_RDWR SD_BOTH
00073 #define ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN WSAEWOULDBLOCK
00074 #ifndef POLLRDNORM
00075 #define POLLRDNORM 0x0100
00076 #endif
00077 #ifndef POLLRDBAND
00078 #define POLLRDBAND 0x0200
00079 #endif
00080 #ifndef POLLIN
00081 #define POLLIN (POLLRDNORM | POLLRDBAND)
00082 #endif
00083 #ifndef POLLPRI
00084 #define POLLPRI 0x0400
00085 #endif
00086
00087 #ifndef POLLWRNORM
00088 #define POLLWRNORM 0x0010
00089 #endif
00090 #ifndef POLLOUT
00091 #define POLLOUT (POLLWRNORM)
00092 #endif
00093 #ifndef POLLWRBAND
00094 #define POLLWRBAND 0x0020
00095 #endif
00096 #ifndef POLLERR
00097 #define POLLERR 0x0001
00098 #endif
00099 #ifndef POLLHUP
00100 #define POLLHUP 0x0002
00101 #endif
00102 #ifndef POLLNVAL
00103 #define POLLNVAL 0x0004
00104 #endif
00105 #else
00106 #define ROS_SOCKETS_SHUT_RDWR SHUT_RDWR
00107 #define ROS_INVALID_SOCKET ((int) -1)
00108 #define ROS_SOCKETS_ASYNCHRONOUS_CONNECT_RETURN EINPROGRESS
00109 #endif
00110
00111
00112
00113
00114
00115 namespace ros {
00116
00117
00118
00119
00120
00121 #ifdef WIN32
00122 typedef SOCKET socket_fd_t;
00123 typedef SOCKET signal_fd_t;
00124
00125 typedef struct socket_pollfd {
00126 socket_fd_t fd;
00127 short events;
00128 short revents;
00129 } socket_pollfd;
00130
00131 typedef unsigned long int nfds_t;
00132 #ifdef _MSC_VER
00133 typedef int pid_t;
00134 #endif
00135 #else
00136 typedef int socket_fd_t;
00137 typedef int signal_fd_t;
00138 typedef struct pollfd socket_pollfd;
00139 #endif
00140
00141
00142
00143
00144
00145 ROSCPP_DECL int last_socket_error();
00146 ROSCPP_DECL const char* last_socket_error_string();
00147 ROSCPP_DECL bool last_socket_error_is_would_block();
00148 ROSCPP_DECL int poll_sockets(socket_pollfd *fds, nfds_t nfds, int timeout);
00149 ROSCPP_DECL int set_non_blocking(socket_fd_t &socket);
00150 ROSCPP_DECL int close_socket(socket_fd_t &socket);
00151 ROSCPP_DECL int create_signal_pair(signal_fd_t signal_pair[2]);
00152
00153
00154
00155
00156
00162 inline void close_signal_pair(signal_fd_t signal_pair[2]) {
00163 #ifdef WIN32 // use a socket pair
00164 ::closesocket(signal_pair[0]);
00165 ::closesocket(signal_pair[1]);
00166 #else // use a socket pair on mingw or pipe pair on linux, either way, close works
00167 ::close(signal_pair[0]);
00168 ::close(signal_pair[1]);
00169 #endif
00170 }
00171
00177 #ifdef _MSC_VER
00178 inline int write_signal(const signal_fd_t &signal, const char *buffer, const unsigned int &nbyte) {
00179 return ::send(signal, buffer, nbyte, 0);
00180
00181 }
00182 #else
00183 inline ssize_t write_signal(const signal_fd_t &signal, const void *buffer, const size_t &nbyte) {
00184 return write(signal, buffer, nbyte);
00185 }
00186 #endif
00187
00188
00194 #ifdef _MSC_VER
00195 inline int read_signal(const signal_fd_t &signal, char *buffer, const unsigned int &nbyte) {
00196 return ::recv(signal, buffer, nbyte, 0);
00197
00198 }
00199 #else
00200 inline ssize_t read_signal(const signal_fd_t &signal, void *buffer, const size_t &nbyte) {
00201 return read(signal, buffer, nbyte);
00202 }
00203 #endif
00204
00205 }
00206
00207 #endif
00208
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Fri Aug 28 2015 12:33:10