18 #ifdef TGT_OS_TYPE_VXWORKS 30 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN 31 #include <arpa/inet.h> 32 #include <sys/socket.h> 35 #error OS not supported for IP Socket Communications 51 struct sockaddr_in address;
54 if ((socketFd = ::socket(AF_INET, SOCK_STREAM, 0)) == -1) {
58 address.sin_family = AF_INET;
59 address.sin_port = htons(this->
m_port);
62 #if defined TGT_OS_TYPE_VXWORKS || TGT_OS_TYPE_DARWIN 63 address.sin_len =
static_cast<U8>(
sizeof(
struct sockaddr_in));
84 if (::connect(socketFd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(address)) < 0) {
88 socketDescriptor.
fd = socketFd;
SocketIpStatus openProtocol(SocketDescriptor &socketDescriptor) override
Tcp specific implementation for opening a client socket.
bool isValidPort(U16 port) override
Check if the given port is valid for the socket.
Failed to connect socket.
Failed to configure socket.
PlatformSizeType FwSizeType
SocketIpStatus recv(const SocketDescriptor &fd, U8 *const data, FwSizeType &size)
receive data from the IP socket from the given buffer
SocketIpStatus setupTimeouts(int socketFd)
setup the socket timeout properties of the opened outgoing socket
static void log(const char *format,...)
log a formated string with supplied arguments
static SocketIpStatus addressToIp4(const char *const ipv4_address, void *const out)
converts a given IPv4 address in dotted-quad form "x.x.x.x" to a network-order in_addr structure...
int fd
Used for all sockets to track the communication file descriptor.
PlatformSignedSizeType FwSignedSizeType
virtual SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size)
send data out the IP socket from the given buffer
U16 m_port
IP address port used.
TcpClientSocket()
Constructor for client socket tcp implementation.
Socket operation successful.
FwSignedSizeType sendProtocol(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size) override
Protocol specific implementation of send. Called directly with retry from send.
SocketIpStatus setupSocketOptions(int socketFd)
setup the socket options of the input socket as defined in IpCfg.hpp
FwSignedSizeType recvProtocol(const SocketDescriptor &socketDescriptor, U8 *const data, const FwSizeType size) override
Protocol specific implementation of recv. Called directly with error handling from recv...
uint8_t U8
8-bit unsigned integer
char m_ipv4_address[SOCKET_MAX_IPV4_ADDRESS_SIZE]
IPv4 address (dotted-quad "x.x.x.x")
void close(const SocketDescriptor &socketDescriptor)
closes the socket
SocketIpStatus
Status enumeration for socket return values.
Helper base-class for setting up Berkeley sockets.