libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
tcpserver.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <promeki/objectbase.h>
14#include <promeki/error.h>
16
17PROMEKI_NAMESPACE_BEGIN
18
19class TcpSocket;
20
40class TcpServer : public ObjectBase {
41 PROMEKI_OBJECT(TcpServer, ObjectBase)
42 public:
47 TcpServer(ObjectBase *parent = nullptr);
48
50 ~TcpServer() override;
51
58 Error listen(const SocketAddress &address, int backlog = 50);
59
61 void close();
62
64 bool isListening() const { return _listening; }
65
67 SocketAddress serverAddress() const { return _address; }
68
77 TcpSocket *nextPendingConnection();
78
92 int nextPendingDescriptor();
93
98 bool hasPendingConnections() const;
99
105 Error waitForNewConnection(unsigned int timeoutMs = 0);
106
111 void setMaxPendingConnections(int count) { _maxPending = count; }
112
123 int socketDescriptor() const { return _fd; }
124
136 Error setNonBlocking(bool enable);
137
139 PROMEKI_SIGNAL(newConnection);
140
141 private:
142 int _fd = -1;
143 bool _listening = false;
144 SocketAddress _address;
145 int _maxPending = 50;
146};
147
148PROMEKI_NAMESPACE_END
149
150#endif // PROMEKI_ENABLE_NETWORK