#ifndef TCPS_CONN_H_ #define TCPS_CONN_H_ /** * @file TCPSConn.h * @brief One accepted connection of a TCPStreamService (internal). * * Ownership: created by the acceptor thread, then owned and deleted by exactly * one TCPSWorker. `streams` and `closeRequested` are the only fields touched * from other threads; `stream` is guarded by the service topology lock, the * queue by `qMutex`. */ #include "CompilerTypes.h" #include "FastPollingMutexSem.h" #include "TCPSFrameQueue.h" #include "TCPStreamService.h" #include "UDPSProtocol.h" #include namespace MARTe { class TCPSWorker; class TCPSServiceStream; struct TCPSConn { TCPSConn(int socketFd, TCPSWorker *owner, uint32 queueDepth, uint64 handshakeDeadline) : fd(socketFd), worker(owner), subscribed(false), hsHave(0u), hsWant(UDPS_HEADER_SIZE), hsHeaderOk(false), hsDeadline(handshakeDeadline), numStreams(0u), closeRequested(false) { for (uint32 i = 0u; i < TCPS_MAX_CONN_STREAMS; i++) { streams[i] = NULL_PTR(TCPSServiceStream *); } q.Init(queueDepth); } ~TCPSConn() { if (fd >= 0) { (void)close(fd); } } int fd; TCPSWorker *worker; /* Worker-thread only. */ bool subscribed; uint8 hs[UDPS_HEADER_SIZE + TCPS_MAX_SUBSCRIBE_PAYLOAD + 1u]; uint32 hsHave; uint32 hsWant; bool hsHeaderOk; uint64 hsDeadline; /* Service topology lock. */ TCPSServiceStream *streams[TCPS_MAX_CONN_STREAMS]; ///< index = stream index on the wire uint32 numStreams; volatile bool closeRequested; /* qMutex. */ FastPollingMutexSem qMutex; TCPSFrameQueue q; private: TCPSConn(const TCPSConn &); TCPSConn &operator=(const TCPSConn &); }; } // namespace MARTe #endif // TCPS_CONN_H_