-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathtcpserver.cc
More file actions
43 lines (35 loc) · 1.06 KB
/
tcpserver.cc
File metadata and controls
43 lines (35 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "tcpserver.hpp"
#include "threadpool.hpp"
#include <QDebug>
class TcpServer::TcpServerPrivate
{
public:
explicit TcpServerPrivate(TcpServer *q)
: q_ptr(q)
{}
TcpServer *q_ptr;
ThreadPool *threadPool = nullptr;
QAtomicInteger<qint32> totalClientCount{0};
QAtomicInteger<qint32> maxClientCount{0};
};
TcpServer::TcpServer(int threadCount, const ConnectionCallbacks &callbacks, QObject *parent)
: QTcpServer(parent)
, d_ptr(new TcpServerPrivate(this))
{
qRegisterMetaType<qintptr>("qintptr");
d_ptr->threadPool = new ThreadPool(threadCount, callbacks, this);
connect(d_ptr->threadPool, &ThreadPool::message, this, &TcpServer::message);
connect(d_ptr->threadPool,
&ThreadPool::clientCountChanged,
this,
&TcpServer::clientCountChanged);
connect(d_ptr->threadPool, &ThreadPool::maxClientCount, this, &TcpServer::maxClientCount);
}
TcpServer::~TcpServer()
{
close();
}
void TcpServer::incomingConnection(qintptr handle)
{
d_ptr->threadPool->dispatchConnection(handle);
}