-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCPConnection.cpp
39 lines (33 loc) · 1.01 KB
/
TCPConnection.cpp
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
#include "TCPConnection.h"
#include "TCPConnectionPrivate.h"
#include "ThreadManager.h"
TCPConnection::TCPConnection() :
_ip( QHostAddress::Any )
, _port( 80 )
, _serverStatus( 0 )
{
if ( !listen(QHostAddress::Any, _port) && _serverStatus == 0 )
qDebug() << QObject::tr("Unable to start the server: %1.").arg(errorString());
else
{
_serverStatus = 1;
qDebug() << "TCPSocket listen on port : " << _port;
qDebug() << "Server started";
}
_threadManager = new ThreadManager( this );
}
TCPConnection::~TCPConnection()
{}
void TCPConnection::incomingConnection(qintptr handle)
{
qDebug() << "New connection!";
auto *connection = new TcpConnectionPrivate( handle );
QThread *thread = _threadManager->GetThread();
connection->moveToThread( thread );
_clients.push_back( connection );
connect( connection, &TcpConnectionPrivate::SocketClosed,
_threadManager, &ThreadManager::SocketClosed );
QMetaObject::invokeMethod(connection,
"Run",
Qt::QueuedConnection);
}