16#ifdef TGT_OS_TYPE_VXWORKS
28#elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
29 #include <sys/socket.h>
31 #include <arpa/inet.h>
33 #error OS not supported for IP Socket Communications
44 struct sockaddr_in address;
47 if ((serverFd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
51 address.sin_family = AF_INET;
52 address.sin_port = htons(this->
m_port);
55#if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN
56 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
65 if (::bind(serverFd,
reinterpret_cast<struct sockaddr*
>(&address),
sizeof(address)) < 0) {
71 if (::listen(serverFd, 0) < 0) {
84 if (this->m_base_fd != -1) {
103 serverFd = this->m_base_fd;
107 clientFd = ::accept(serverFd,
nullptr,
nullptr);
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 Berkeley sockets.
void close()
closes the socket
U16 m_port
IP address port used.
bool isStarted()
Returns true when the socket is started.
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
virtual void shutdown()
shutdown the socket
virtual SocketIpStatus startup()
startup the socket, a no-op on unless this is server
TcpServerSocket()
Constructor for client socket tcp implementation.
I32 sendProtocol(const U8 *const data, const U32 size) override
Protocol specific implementation of send. Called directly with retry from send.
SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd) override
Tcp specific implementation for opening a client socket connected to this server.
void shutdown() override
Shutdown and close the server socket followed by the open client.
I32 recvProtocol(U8 *const data, const U32 size) override
Protocol specific implementation of recv. Called directly with error handling from recv.
SocketIpStatus startup() override
Opens the server socket and listens, does not block.
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)
void unLock()
unlock the mutex
void lock()
lock the mutex
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.
@ SOCK_NOT_STARTED
Socket has not been started.