24 #ifdef TGT_OS_TYPE_VXWORKS 36 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN 37 #include <arpa/inet.h> 38 #include <sys/socket.h> 42 #error OS not supported for IP Socket Communications 53 const U32 timeout_seconds,
54 const U32 timeout_microseconds) {
55 FW_ASSERT(timeout_microseconds < 1000000, static_cast<FwAssertArgType>(timeout_microseconds));
71 #ifdef TGT_OS_TYPE_VXWORKS 75 struct timeval timeout;
79 if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, reinterpret_cast<char*>(&timeout),
sizeof(timeout)) < 0) {
90 #ifdef TGT_OS_TYPE_VXWORKS 91 int ip = inet_addr(address);
97 *
reinterpret_cast<unsigned long*
>(ip4) = ip;
100 if (not ::inet_pton(AF_INET, address, ip4)) {
108 (void)::
close(socketDescriptor.
fd);
113 int status =
::shutdown(socketDescriptor.
fd, SHUT_RDWR);
116 this->
close(socketDescriptor);
126 socketDescriptor.
fd = -1;
142 sent = this->
sendProtocol(socketDescriptor, data + total, size - total);
144 if (((sent == -1) && (errno == EINTR)) || (sent == 0)) {
148 else if ((sent == -1) && ((errno == EBADF) || (errno == ECONNRESET))) {
152 else if (sent == -1) {
155 FW_ASSERT(sent > 0, static_cast<FwAssertArgType>(sent));
163 FW_ASSERT(total == size, static_cast<FwAssertArgType>(total), static_cast<FwAssertArgType>(size));
180 bytes_received_or_status = this->
recvProtocol(socketDescriptor, data, req_read);
182 if (bytes_received_or_status > 0) {
184 req_read =
static_cast<FwSizeType>(bytes_received_or_status);
186 }
else if (bytes_received_or_status == 0) {
191 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
195 }
else if ((errno == ECONNRESET) || (errno == EBADF)) {
222 status = setsockopt(socketFd, options.level, options.option, &options.value.intVal,
223 sizeof(options.value.intVal));
225 status = setsockopt(socketFd, options.level, options.option, &options.value.sizeVal,
226 sizeof(options.value.sizeVal));
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.
Failed to send after configured retries.
virtual bool isValidPort(U16 port)
Check if the given port is valid for the socket.
Failed to read socket with disconnect.
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
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
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
uint8_t U8
8-bit unsigned integer
virtual SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with host and transmission timeouts
static const IpSocketOptions IP_SOCKET_OPTIONS[]
virtual SocketIpStatus handleZeroReturn()
Handle zero return from recvProtocol.
void close(const SocketDescriptor &socketDescriptor)
closes the socket
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
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.