 |
F´ Flight Software - C/C++ Documentation
NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
|
Go to the documentation of this file.
14 #include <Fw/Types/Assert.hpp>
15 #include <Fw/Types/BasicTypes.hpp>
24 #ifdef TGT_OS_TYPE_VXWORKS
37 #elif defined TGT_OS_TYPE_LINUX || TGT_OS_TYPE_DARWIN
38 #include <sys/socket.h>
41 #include <arpa/inet.h>
43 #error OS not supported for IP Socket Communications
49 IpSocket::IpSocket() : m_fd(-1), m_timeoutSeconds(0), m_timeoutMicroseconds(0), m_port(0), m_open(false) {
54 FW_ASSERT(timeout_microseconds < 1000000, timeout_microseconds);
65 #ifdef TGT_OS_TYPE_VXWORKS
69 struct timeval timeout;
73 if (setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO,
reinterpret_cast<char *
>(&timeout),
sizeof(timeout)) < 0) {
84 #ifdef TGT_OS_TYPE_VXWORKS
91 *
reinterpret_cast<unsigned long*
>(ip4) = ip;
94 if (not ::inet_pton(AF_INET, address, ip4)) {
102 bool is_open =
false;
111 if (this->
m_fd != -1) {
112 (void)::shutdown(this->
m_fd, SHUT_RDWR);
142 if (this->
m_fd == -1) {
150 if (((sent == -1) && (errno == EINTR)) || (sent == 0)) {
154 else if ((sent == -1) && ((errno == EBADF) || (errno == ECONNRESET))) {
159 else if (sent == -1) {
185 if (size == -1 && ((errno == EINTR) || errno == EAGAIN)) {
189 else if (size == 0 || ((size == -1) && ((errno == ECONNRESET) || (errno == EBADF)))) {
195 else if (size == -1) {
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
void close()
closes the socket
@ SOCK_FAILED_TO_SET_SOCKET_OPTIONS
Failed to configure socket.
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
virtual SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd)=0
Protocol specific open implementation, called from open.
SocketIpStatus setupTimeouts(NATIVE_INT_TYPE socketFd)
setup the socket timeout properties of the opened outgoing socket
virtual I32 sendProtocol(const U8 *const data, const U32 size)=0
Protocol specific implementation of send. Called directly with retry from send.
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
bool isOpened()
check if IP socket has previously been opened
U32 m_timeoutMicroseconds
virtual I32 recvProtocol(U8 *const data, const U32 size)=0
Protocol specific implementation of recv. Called directly with error handling from recv.
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
void lock()
lock the mutex
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
bool m_open
Have we successfully opened.
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
@ SOCK_SUCCESS
Socket operation successful.
@ SOCK_READ_ERROR
Failed to read socket.
SocketIpStatus
Status enumeration for socket return values.
void unLock()
unlock the mutex
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 recv(U8 *const data, I32 &size)
receive data from the IP socket from the given buffer
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
@ SOCKET_MAX_HOSTNAME_SIZE
@ SOCK_SEND_ERROR
Failed to send after configured retries.
U16 m_port
IP address port used.
SocketIpStatus open()
open the IP socket for communications