#ifndef TCPS_WORKER_H_ #define TCPS_WORKER_H_ /** * @file TCPSWorker.h * @brief One I/O thread of a TCPStreamService (internal). * * Owns a set of connections, polls them (plus a self-pipe used by producers to * announce new frames), performs the SUBSCRIBE handshake, flushes the bounded * queues and evicts stalled / dead peers. */ #include "EmbeddedServiceMethodBinderI.h" #include "ExecutionInfo.h" #include "FastPollingMutexSem.h" #include "SingleThreadService.h" #include namespace MARTe { class TCPStreamService; struct TCPSConn; class TCPSWorker : public EmbeddedServiceMethodBinderI { public: TCPSWorker(TCPStreamService &owner, uint32 maxConns); virtual ~TCPSWorker(); bool Start(uint32 cpuMask, uint32 stackSize); void Stop(); /** Hand a freshly accepted connection to this worker (acceptor thread). */ bool AddIncoming(TCPSConn *c); /** Interrupt the poll so queued data is flushed now (any thread, cheap). */ void Wake(); /** @return connections currently assigned (approximate). */ int32 Load() const; virtual ErrorManagement::ErrorType Execute(ExecutionInfo &info); private: void AdoptIncoming(); bool HandshakeStep(TCPSConn &c); bool Drain(TCPSConn &c); void CloseConn(TCPSConn *c); void CloseAll(); TCPStreamService &service; uint32 maxConns; SingleThreadService thread; int wakeFd[2]; FastPollingMutexSem incomingMutex; TCPSConn **incoming; uint32 numIncoming; TCPSConn **conns; uint32 numConns; struct pollfd *pfds; volatile int32 load; }; } // namespace MARTe #endif // TCPS_WORKER_H_