Go to the documentation of this file.
32 #ifndef SIMPLE_SOCKET_H
33 #define SIMPLE_SOCKET_H
46 #if defined(SIMPLE_MESSAGE_LINUX) || defined(LINUXSOCKETS)
49 #include "sys/socket.h"
50 #include "arpa/inet.h"
52 #include "netinet/tcp.h"
59 #define SOCKET(domain, type, protocol) socket(domain, type, protocol)
60 #define BIND(sockfd, addr, addrlen) bind(sockfd, addr, addrlen)
61 #define SET_NO_DELAY(sockfd, val) setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<const char*>(&(val)), sizeof(val))
62 #define SET_REUSE_ADDR(sockfd, val) setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char*>(&(val)), sizeof(val))
63 #define LISTEN(sockfd, n) listen(sockfd, n)
64 #define ACCEPT(sockfd, addr, addrlen) accept(sockfd, addr, addrlen)
65 #define CONNECT(sockfd, dest_addr ,addrlen) connect(sockfd, dest_addr, addrlen)
66 #define SEND_TO(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen)
67 #define SEND(sockfd, buf, len, flags) send(sockfd, buf, len, flags)
68 #define RECV_FROM(sockfd, buf, len, flags, src_addr, addrlen) recvfrom(sockfd, buf, len, flags, src_addr, addrlen)
69 #define RECV(sockfd, buf, len, flags) recv(sockfd, buf, len, flags)
70 #define SELECT(n, readfds, writefds, exceptfds, timeval) select(n, readfds, writefds, exceptfds, timeval)
72 #define CLOSE(fd) closesocket(fd)
74 #define CLOSE(fd) close(fd)
76 #ifndef HTONS // OSX defines HTONS
77 #define HTONS(num) htons(num)
79 #define INET_ADDR(str) inet_addr(str)
80 #define SOCKLEN_T socklen_t
81 #define GETADDRINFO(node, service, hints, results) getaddrinfo(node, service, hints, results)
85 #ifdef SIMPLE_MESSAGE_MOTOPLUS
94 extern "C" STATUS setsockopt (
102 #define SOCKET(domain, type, protocol) mpSocket(domain, type, protocol)
103 #define BIND(sockfd, addr, addrlen) mpBind(sockfd, addr, addrlen)
108 #define SET_NO_DELAY(sockfd, val) setsockopt(sockfd, SOL_SOCKET, TCP_NODELAY, (char *)&val, sizeof(val))
110 #define SET_REUSE_ADDR(sockfd, val) -1 //MOTOPLUS does not support this function.
111 #define LISTEN(sockfd, n) mpListen(sockfd, n)
112 #define ACCEPT(sockfd, addr, addrlen) mpAccept(sockfd, addr, addrlen)
113 #define CONNECT(sockfd, dest_addr ,addrlen) mpConnect(sockfd, dest_addr, addrlen)
114 #define SEND_TO(sockfd, buf, len, flags, dest_addr, addrlen) mpSendTo(sockfd, buf, len, flags, dest_addr, addrlen)
115 #define SEND(sockfd, buf, len, flags) mpSend(sockfd, buf, len, flags)
116 #define RECV_FROM(sockfd, buf, len, flags, src_addr, addrlen) mpRecvFrom(sockfd, buf, len, flags, src_addr, (int*)addrlen)
117 #define RECV(sockfd, buf, len, flags) mpRecv(sockfd, buf, len, flags)
118 #define SELECT(n, readfds, writefds, exceptfds, timeval) mpSelect(n, readfds, writefds, exceptfds, timeval)
119 #define CLOSE(fd) mpClose(fd)
120 #define HTONS(num) mpHtons(num)
121 #define INET_ADDR(str) mpInetAddr(str)
122 #define SOCKLEN_T unsigned int
123 #define GETHOSTBYNAME(str) NULL
129 namespace simple_socket
137 namespace StandardSocketPorts
252 "Please use: logSocketError(const char* msg, const int rc, const int error_no)")))
267 LOG_ERROR(
"%s, rc: %d. Error: '%s' (errno: %d)", msg,
rc, strerror(error_no), error_no);
291 virtual bool rawPoll(
int timeout,
bool & ready,
bool & error)=0;
294 this->connected_ = connected;
bool receiveBytes(industrial::byte_array::ByteArray &buffer, industrial::shared_types::shared_int num_bytes, industrial::shared_types::shared_int timeout_ms)
Method used by receive message interface method. This should be overridden for the specific connectio...
bool connected_
flag indicating socket connection status
static const int SOCKET_POLL_TO
socket ready polling timeout (ms)
static const int MAX_BUFFER_SIZE
maximum size of buffer for receiving data (fixed memory size used in order to avoid dynamic memory al...
virtual ~SimpleSocket()
Destructor.
virtual int rawSendBytes(char *buffer, industrial::shared_types::shared_int num_bytes)=0
StandardSocketPorts::StandardSocketPort StandardSocketPort
int getSockHandle() const
bool isConnected()
return connection status
virtual int rawReceiveBytes(char *buffer, industrial::shared_types::shared_int num_bytes)=0
__attribute__((deprecated("Please use: logSocketError(const char* msg, const int rc, const int error_no)"))) void logSocketError(const char *msg
Logs message to error log and reports associated socket system error.
#define LOG_ERROR(format,...)
bool isReadyReceive(int timeout)
returns true if socket data is ready to receive
sockaddr_in sockaddr_
address/port of remote socket
void logSocketError(const char *msg, const int rc, const int error_no)
Logs message to error log and reports associated socket system error.
The byte array wraps a dynamic array of bytes (i.e. char).
virtual void setDisconnected()
char buffer_[MAX_BUFFER_SIZE+1]
internal data buffer for receiving
SimpleSocket()
Constructor.
void setSockHandle(int sock_handle_)
Defines an interface and common methods for sending simple messages (see simple_message)....
int sock_handle_
socket handle for sending/receiving data
static const int SOCKET_FAIL
socket fail return value
virtual bool rawPoll(int timeout, bool &ready, bool &error)=0
polls socket for data or error
bool sendBytes(industrial::byte_array::ByteArray &buffer)
Method used by send message interface method. This should be overridden for the specific connection t...
Defines socket functions required for a simple connection type.
virtual void setConnected(bool connected)
simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53