TCP server that listens for incoming connections. More...
#include <tcpserver.h>


Public Member Functions | |
| TcpServer (ObjectBase *parent=nullptr) | |
| Constructs a TcpServer. | |
| ~TcpServer () override | |
| Destructor. Closes the server if listening. | |
| Error | listen (const SocketAddress &address, int backlog=50) |
| Starts listening for connections. | |
| void | close () |
| Stops listening and closes the server socket. | |
| bool | isListening () const |
| Returns true if the server is listening. | |
| SocketAddress | serverAddress () const |
| Returns the address the server is listening on. | |
| TcpSocket * | nextPendingConnection () |
| Returns the next accepted connection. | |
| bool | hasPendingConnections () const |
| Returns true if there are pending connections. | |
| Error | waitForNewConnection (unsigned int timeoutMs=0) |
| Blocks until a new connection arrives or timeout. | |
| void | setMaxPendingConnections (int count) |
| Sets the maximum number of pending connections. | |
| PROMEKI_SIGNAL (newConnection) | |
| Emitted when a new connection is available. | |
Public Member Functions inherited from ObjectBase | |
| ObjectBase (ObjectBase *p=nullptr) | |
| Default ObjectBase constructor. | |
| virtual | ~ObjectBase () |
| Destructor. Emits aboutToDestroy, detaches from parent, and destroys children. | |
| ObjectBase * | parent () const |
| Returns the parent object, if one. nullptr if none. | |
| void | setParent (ObjectBase *p) |
| Sets the parent of this object. If the object already has a parent, it will be removed as a child from the old parent and added as a child to the new one. | |
| const ObjectBaseList & | childList () const |
| Returns a list of children of this object. | |
| template<typename... Args> | |
| int | registerSlot (Slot< Args... > *slot) |
| Registers a slot with this object and assigns it an ID. | |
| EventLoop * | eventLoop () const |
| Returns the EventLoop this object is affiliated with. | |
| void | moveToThread (EventLoop *loop) |
| Changes the EventLoop affinity of this object. | |
| int | startTimer (unsigned int intervalMs, bool singleShot=false) |
| Starts a timer on this object's EventLoop. | |
| void | stopTimer (int timerId) |
| Stops a timer previously started with startTimer(). | |
| template<typename... Args> | |
| PROMEKI_NAMESPACE_BEGIN void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
Additional Inherited Members | |
Public Types inherited from ObjectBase | |
| using | SlotVariantFunc = std::function< void(const VariantList &)> |
| Function type for invoking a slot with a list of Variants. | |
Static Public Member Functions inherited from ObjectBase | |
| static const MetaInfo & | metaInfo () |
| Returns the MetaInfo for the ObjectBase class. | |
| template<typename... Args> | |
| static void | connect (Signal< Args... > *signal, Slot< Args... > *slot) |
| connects a signal and slot together. This function assumes both the signal and slot exist in a ObjectBase or derived object | |
Public Attributes inherited from ObjectBase | |
| Signal< ObjectBase * > | aboutToDestroySignal = Signal< ObjectBase * >(this, aboutToDestroySignalName) |
Static Public Attributes inherited from ObjectBase | |
| static constexpr const char * | aboutToDestroySignalName = PROMEKI_STRINGIFY( aboutToDestroy ) "(" PROMEKI_STRINGIFY_ARGS( ObjectBase * ) ")" |
| static SignalMeta | aboutToDestroySignalMeta = SignalMeta(metaInfo(), aboutToDestroySignalName) |
Protected Member Functions inherited from ObjectBase | |
| ObjectBase * | signalSender () |
| Returns the ObjectBase that emitted the signal currently being handled. | |
| virtual void | event (Event *e) |
| Called by EventLoop to deliver events to this object. | |
| virtual void | timerEvent (TimerEvent *e) |
| Called when a timer fires for this object. | |
TCP server that listens for incoming connections.
TcpServer binds to a local address and listens for incoming TCP connections. Accepted connections are returned as TcpSocket objects.
This class must only be used from the thread that created it (or moved to via moveToThread()).
| TcpServer::TcpServer | ( | ObjectBase * | parent = nullptr | ) |
Constructs a TcpServer.
| parent | The parent object, or nullptr. |
| bool TcpServer::hasPendingConnections | ( | ) | const |
Returns true if there are pending connections.
| Error TcpServer::listen | ( | const SocketAddress & | address, |
| int | backlog = 50 |
||
| ) |
Starts listening for connections.
| address | The local address and port to listen on. |
| backlog | The maximum pending connection queue length. |
| TcpSocket * TcpServer::nextPendingConnection | ( | ) |
| TcpServer::PROMEKI_SIGNAL | ( | newConnection | ) |
Emitted when a new connection is available.
|
inline |
Sets the maximum number of pending connections.
| count | The maximum count. |
Blocks until a new connection arrives or timeout.
| timeoutMs | Timeout in milliseconds (0 = wait forever). |