24 #ifdef TGT_OS_TYPE_VXWORKS
37 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
38 #include <sys/socket.h>
41 #include <arpa/inet.h>
43 #error OS not supported for IP Socket Communications
70 #ifdef TGT_OS_TYPE_VXWORKS
74 struct timeval timeout;
78 if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO,
reinterpret_cast<char *
>(&timeout),
sizeof(timeout)) < 0) {
89 #ifdef TGT_OS_TYPE_VXWORKS
96 *
reinterpret_cast<unsigned long*
>(ip4) = ip;
99 if (not ::inet_pton(AF_INET, address, ip4)) {
107 (void)::
close(socketDescriptor.
fd);
115 this->
close(socketDescriptor);
125 socketDescriptor.
fd = -1;
138 sent = this->
sendProtocol(socketDescriptor, data + total, size - total);
140 if (((sent == -1) && (errno == EINTR)) || (sent == 0)) {
144 else if ((sent == -1) && ((errno == EBADF) || (errno == ECONNRESET))) {
148 else if (sent == -1) {
152 total +=
static_cast<U32
>(sent);
169 size = this->
recvProtocol(socketDescriptor, data, req_read);
172 if ((size == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) {
178 if ((size == -1) && (errno == EINTR)) {
182 else if (size == 0 || ((size == -1) && ((errno == ECONNRESET) || (errno == EBADF)))) {
183 req_read =
static_cast<U32
>(size);
187 else if (size == -1) {
188 req_read =
static_cast<U32
>(size);
192 req_read =
static_cast<U32
>(size);
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformAssertArgType FwAssertArgType
PlatformSizeType FwSizeType
C++-compatible configuration header for fprime configuration.
@ SOCKET_MAX_HOSTNAME_SIZE
U16 m_port
IP address port used.
virtual SocketIpStatus openProtocol(SocketDescriptor &fd)=0
Protocol specific open implementation, called from open.
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
SocketIpStatus setupTimeouts(PlatformIntType socketFd)
setup the socket timeout properties of the opened outgoing socket
SocketIpStatus open(SocketDescriptor &socketDescriptor)
open the IP socket for communications
SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with host and transmission timeouts
virtual I32 sendProtocol(const SocketDescriptor &socketDescriptor, const U8 *const data, const U32 size)=0
Protocol specific implementation of send. Called directly with retry from send.
U32 m_timeoutMicroseconds
static SocketIpStatus addressToIp4(const char *address, void *ip4)
converts a given address in dot form x.x.x.x to an ip address. ONLY works for IPv4.
virtual bool isValidPort(U16 port)
Check if the given port is valid for the socket.
virtual I32 recvProtocol(const SocketDescriptor &socketDescriptor, U8 *const data, const U32 size)=0
Protocol specific implementation of recv. Called directly with error handling from recv.
SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
void shutdown(const SocketDescriptor &socketDescriptor)
shutdown the socket
SocketIpStatus recv(const SocketDescriptor &fd, U8 *const data, U32 &size)
receive data from the IP socket from the given buffer
void close(const SocketDescriptor &socketDescriptor)
closes the socket
SocketIpStatus
Status enumeration for socket return values.
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
@ SOCK_SUCCESS
Socket operation successful.
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
@ SOCK_READ_ERROR
Failed to read socket.
@ SOCK_FAILED_TO_SET_SOCKET_OPTIONS
Failed to configure socket.
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
@ SOCK_SEND_ERROR
Failed to send after configured retries.
@ SOCK_NO_DATA_AVAILABLE
No data available or read operation would block.
char * string_copy(char *destination, const char *source, FwSizeType num)
copy string with null-termination guaranteed
PlatformIntType fd
Used for all sockets to track the communication file descriptor.