libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
tcpserver.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <promeki/core/error.h>
13
15
16class TcpSocket;
17
36class TcpServer : public ObjectBase {
37 PROMEKI_OBJECT(TcpServer, ObjectBase)
38 public:
44
46 ~TcpServer() override;
47
54 Error listen(const SocketAddress &address, int backlog = 50);
55
57 void close();
58
60 bool isListening() const { return _listening; }
61
63 SocketAddress serverAddress() const { return _address; }
64
74
80
87
92 void setMaxPendingConnections(int count) { _maxPending = count; }
93
96
97 private:
98 int _fd = -1;
99 bool _listening = false;
100 SocketAddress _address;
101 int _maxPending = 50;
102};
103
Lightweight error code wrapper for the promeki library.
Definition error.h:39
Dynamic array container wrapping std::vector.
Definition list.h:40
Base object for promeki.
Definition objectbase.h:129
ObjectBase * parent() const
Returns the parent object, if one. nullptr if none.
Definition objectbase.h:258
Network address with port number.
Definition socketaddress.h:50
TCP server that listens for incoming connections.
Definition tcpserver.h:36
bool isListening() const
Returns true if the server is listening.
Definition tcpserver.h:60
void setMaxPendingConnections(int count)
Sets the maximum number of pending connections.
Definition tcpserver.h:92
Error waitForNewConnection(unsigned int timeoutMs=0)
Blocks until a new connection arrives or timeout.
void close()
Stops listening and closes the server socket.
TcpServer(ObjectBase *parent=nullptr)
Constructs a TcpServer.
~TcpServer() override
Destructor. Closes the server if listening.
SocketAddress serverAddress() const
Returns the address the server is listening on.
Definition tcpserver.h:63
Error listen(const SocketAddress &address, int backlog=50)
Starts listening for connections.
TcpSocket * nextPendingConnection()
Returns the next accepted connection.
bool hasPendingConnections() const
Returns true if there are pending connections.
PROMEKI_SIGNAL(newConnection)
Emitted when a new connection is available.
Stream-oriented TCP socket.
Definition tcpsocket.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19