18 #ifdef TGT_OS_TYPE_VXWORKS 30 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN 31 #include <sys/socket.h> 33 #include <arpa/inet.h> 35 #error OS not supported for IP Socket Communications 52 struct sockaddr_in address;
55 if ((socketFd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
59 address.sin_family = AF_INET;
60 address.sin_port = htons(this->
m_port);
63 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN 64 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
80 if (::connect(socketFd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(address)) < 0) {
84 socketDescriptor.
fd = socketFd;
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 openProtocol(SocketDescriptor &socketDescriptor) override
Tcp specific implementation for opening a client socket.
I32 sendProtocol(const SocketDescriptor &socketDescriptor, const U8 *const data, const U32 size) override
Protocol specific implementation of send. Called directly with retry from send.
bool isValidPort(U16 port) override
Check if the given port is valid for the socket.
SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Failed to connect socket.
Failed to configure socket.
PlatformIntType NATIVE_INT_TYPE
static void log(const char *format,...)
log a formated string with supplied arguments
SocketIpStatus recv(const SocketDescriptor &fd, U8 *const data, U32 &size)
receive data from the IP socket from the given buffer
U16 m_port
IP address port used.
TcpClientSocket()
Constructor for client socket tcp implementation.
Socket operation successful.
SocketIpStatus setupTimeouts(PlatformIntType socketFd)
setup the socket timeout properties of the opened outgoing socket
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
PlatformIntType fd
Used for all sockets to track the communication file descriptor.
void close(const SocketDescriptor &socketDescriptor)
closes the socket
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
I32 recvProtocol(const SocketDescriptor &socketDescriptor, U8 *const data, const U32 size) override
Protocol specific implementation of recv. Called directly with error handling from recv...
SocketIpStatus
Status enumeration for socket return values.
Helper base-class for setting up Berkeley sockets.