44 if (this->
m_open == OpenState::NOT_OPEN) {
45 this->
m_open = OpenState::OPENING;
48 local_open = OpenState::SKIP;
52 if (local_open == OpenState::OPENING) {
59 this->
m_open = OpenState::OPEN;
61 this->
m_open = OpenState::NOT_OPEN;
76 bool is_open = this->
m_open == OpenState::OPEN;
84 status = this->
open();
98 if (descriptor.
fd == -1) {
125 this->
m_open = OpenState::NOT_OPEN;
153 if (descriptor.
fd == -1) {
170 Fw::Logger::log(
"[WARNING] Failed to open port with status %d and errno %d\n", status, errno);
182 status = this->
recv(data, size);
184 Fw::Logger::log(
"[WARNING] Failed to recv from port with status %d and errno %d\n",
uint8_t U8
8-bit unsigned integer
PlatformAssertArgType FwAssertArgType
static const Fw::TimeInterval SOCKET_RETRY_INTERVAL
SocketIpStatus open(SocketDescriptor &socketDescriptor)
open the IP socket for communications
SocketIpStatus send(const SocketDescriptor &socketDescriptor, const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
void shutdown(const SocketDescriptor &socketDescriptor)
shutdown the socket
SocketIpStatus recv(const SocketDescriptor &fd, U8 *const data, U32 &size)
receive data from the IP socket from the given buffer
void close(const SocketDescriptor &socketDescriptor)
closes the socket
supports a task to read a given socket adaptation
virtual void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)=0
sends a buffer to be filled with data
SocketDescriptor m_descriptor
bool isOpened()
check if IP socket has previously been opened
SocketComponentHelper()
constructs the socket read task
void start(const Fw::StringBase &name, const bool reconnect=true, const Os::Task::ParamType priority=Os::Task::TASK_DEFAULT, const Os::Task::ParamType stack=Os::Task::TASK_DEFAULT, const Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT)
start the socket read task to start producing data
bool m_reconnect
Force reconnection.
OpenState m_open
Have we successfully opened.
virtual Fw::Buffer getBuffer()=0
returns a buffer to fill with data
virtual IpSocket & getSocketHandler()=0
returns a reference to the socket handler
virtual void readLoop()
receive off the TCP socket
bool m_stop
Stops the task when set to true.
virtual void connected()=0
called when the IPv4 system has been connected
void close()
close the socket communications
void shutdown()
shutdown the socket communications
Os::Task::Status join()
joins to the stopping read task to wait for it to close
SocketIpStatus open()
open the socket for communications
SocketIpStatus recv(U8 *data, U32 &size)
receive data from the IP socket from the given buffer
SocketIpStatus send(const U8 *const data, const U32 size)
send data to the IP socket from the given buffer
SocketIpStatus reconnect()
Re-open port if it has been disconnected.
bool running()
is the read loop running
void stop()
stop the socket read task and close the associated socket.
virtual ~SocketComponentHelper()
destructor of the socket read task
static void readTask(void *pointer)
a task designed to read from the socket and output incoming data
static void log(const char *format,...)
log a formated string with supplied arguments
void unlock()
alias for unLock to meet BasicLockable requirements
void lock()
lock the mutex and assert success
locks a mutex within the current scope
static Status delay(Fw::TimeInterval interval)
delay the current task
State getState()
get the task's state
FwSizeType ParamType
backwards-compatible parameter type
Status start(const Arguments &arguments) override
start the task
Status join() override
block until the task has ended
@ OP_OK
message sent/received okay
SocketIpStatus
Status enumeration for socket return values.
@ SOCK_SUCCESS
Socket operation successful.
@ SOCK_ANOTHER_THREAD_OPENING
Another thread is opening.
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
@ SOCK_NO_DATA_AVAILABLE
No data available or read operation would block.
PlatformIntType fd
Used for all sockets to track the communication file descriptor.