17#ifdef TGT_OS_TYPE_VXWORKS
29#elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
30 #include <sys/socket.h>
32 #include <arpa/inet.h>
34 #error OS not supported for IP Socket Communications
45 struct sockaddr_in address;
49 if ((serverFd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
53 address.sin_family = AF_INET;
54 address.sin_port = htons(this->
m_port);
57#if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN
58 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
67 if (::bind(serverFd,
reinterpret_cast<struct sockaddr*
>(&address),
sizeof(address)) < 0) {
74 if (::listen(serverFd, 0) < 0) {
91 if ((clientFd = ::accept(m_base_fd,
nullptr,
nullptr)) < 0) {
PlatformPointerCastType POINTER_CAST
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
C++-compatible configuration header for fprime configuration.
Helper base-class for setting up Berkley sockets.
void close()
closes the socket
U16 m_port
IP address port used.
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
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.
SocketIpStatus setupTimeouts(NATIVE_INT_TYPE socketFd)
setup the socket timeout properties of the opened outgoing socket
TcpServerSocket()
Constructor for client socket tcp implementation.
void shutdown()
Shutdown client socket, and listening server socket.
I32 sendProtocol(const U8 *const data, const U32 size)
Protocol specific implementation of send. Called directly with retry from send.
SocketIpStatus startup()
Opens the server socket and listens, does not block.
SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd)
Tcp specific implementation for opening a client socket connected to this server.
I32 recvProtocol(U8 *const data, const U32 size)
Protocol specific implementation of recv. Called directly with error handling from recv.
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
SocketIpStatus
Status enumeration for socket return values.
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
@ SOCK_FAILED_TO_ACCEPT
Failed to accept connection.
@ SOCK_SUCCESS
Socket operation successful.
@ SOCK_FAILED_TO_BIND
Failed to bind to socket.
@ SOCK_FAILED_TO_SET_SOCKET_OPTIONS
Failed to configure socket.
@ SOCK_FAILED_TO_GET_SOCKET
Socket open failed.
@ SOCK_FAILED_TO_LISTEN
Failed to listen on socket.