32 const U32 timeout_seconds,
33 const U32 timeout_microseconds) {
34 FW_ASSERT(timeout_microseconds < 1000000, static_cast<FwAssertArgType>(timeout_microseconds));
56 #ifdef TGT_OS_TYPE_VXWORKS 60 struct timeval timeout;
64 if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char*>(&timeout),
sizeof(timeout)) < 0) {
73 constexpr
int enable = 1;
74 if (setsockopt(socketFd, SOL_SOCKET, SO_NOSIGPIPE, &enable,
sizeof(enable)) < 0) {
88 (void)::memset(out, 0,
sizeof(
struct in_addr));
90 #ifdef TGT_OS_TYPE_VXWORKS 91 int ip = inet_addr(ipv4_address);
97 *
static_cast<unsigned long*
>(out) = static_cast<unsigned long>(ip);
103 const int ptonStatus = ::inet_pton(AF_INET, ipv4_address, out);
104 if (ptonStatus != 1) {
112 if (socketDescriptor.
fd >= 0) {
113 (void)::
close(socketDescriptor.
fd);
119 int status =
::shutdown(socketDescriptor.
fd, SHUT_RDWR);
122 this->
close(socketDescriptor);
132 socketDescriptor.
fd = -1;
139 FW_ASSERT((size == 0) || (data !=
nullptr));
151 sent = this->
sendProtocol(socketDescriptor, data + total, size - total);
153 if (((sent == -1) && (errno == EINTR)) || (sent == 0)) {
157 else if ((sent == -1) && ((errno == EBADF) || (errno == ECONNRESET) || (errno == EPIPE))) {
161 else if ((sent == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK))) {
165 else if (sent == -1) {
168 FW_ASSERT(sent > 0, static_cast<FwAssertArgType>(sent));
176 FW_ASSERT(total == size, static_cast<FwAssertArgType>(total), static_cast<FwAssertArgType>(size));
193 bytes_received_or_status = this->
recvProtocol(socketDescriptor, data, req_read);
195 if (bytes_received_or_status > 0) {
197 req_read =
static_cast<FwSizeType>(bytes_received_or_status);
199 }
else if (bytes_received_or_status == 0) {
204 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
208 }
else if ((errno == ECONNRESET) || (errno == EBADF)) {
212 }
else if (errno == EINTR) {
237 status = setsockopt(socketFd, options.level, options.option, &options.value.intVal,
238 sizeof(options.value.intVal));
240 status = setsockopt(socketFd, options.level, options.option, &options.value.sizeVal,
241 sizeof(options.value.sizeVal));
Failed to send after configured retries.
Socket disconnected during read or send.
Interrupted status for retries.
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
virtual SocketIpStatus configure(const char *const ipv4_address, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with an IPv4 address and transmission timeouts
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
SocketIpStatus setupNoSigPipe(int socketFd)
prevent sends on a stream socket from raising SIGPIPE on platforms without MSG_NOSIGNAL ...
virtual SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size)
send data out the IP socket from the given buffer
virtual SocketIpStatus openProtocol(SocketDescriptor &fd)=0
Protocol specific open implementation, called from open.
void shutdown(const SocketDescriptor &socketDescriptor)
shutdown the socket
virtual FwSignedSizeType sendProtocol(const SocketDescriptor &socketDescriptor, const U8 *const data, const FwSizeType size)=0
Protocol specific implementation of send. Called directly with retry from send.
U16 m_port
IP address port used.
Socket operation successful.
char * string_copy(char *destination, const char *source, FwSizeType num)
copy string with null-termination guaranteed
SocketIpStatus setupSocketOptions(int socketFd)
setup the socket options of the input socket as defined in IpCfg.hpp
virtual bool isValidPort(U16 port) const
Check if the given port is valid for the socket.
uint8_t U8
8-bit unsigned integer
static const IpSocketOptions IP_SOCKET_OPTIONS[]
virtual SocketIpStatus handleZeroReturn()
Handle zero return from recvProtocol.
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
virtual FwSignedSizeType recvProtocol(const SocketDescriptor &socketDescriptor, U8 *const data, const FwSizeType size)=0
Protocol specific implementation of recv. Called directly with error handling from recv...
SocketIpStatus open(SocketDescriptor &socketDescriptor)
open the IP socket for communications
SocketIpStatus
Status enumeration for socket return values.
U32 m_timeoutMicroseconds
No data available or read operation would block.
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string