-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpserverwrapper.cpp
More file actions
58 lines (44 loc) · 1.71 KB
/
tcpserverwrapper.cpp
File metadata and controls
58 lines (44 loc) · 1.71 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "tcpserverwrapper.h"
#include <QTcpSocket>
#include "logger.hpp"
void TcpServerWrapper::incomingConnection(qintptr handle)
{
LOGGING_LEVEL("debug")<<"@incomingConnection() handle"<<handle;
QTcpServer::incomingConnection(handle);
}
TcpConnectionDelegate::TcpConnectionDelegate(QObject *parent)
:QObject(parent)
,mTcpServer((QTcpServer*)(new TcpServerWrapper(this)))
{
connect(mTcpServer, SIGNAL(newConnection()), this, SLOT(onReadyForConnecting()));
connect(mTcpServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(onAcceptError(QAbstractSocket::SocketError)));
mTcpServer->setMaxPendingConnections(90);
}
TcpConnectionDelegate::~TcpConnectionDelegate()
{
}
bool TcpConnectionDelegate::listen(const QHostAddress &address, quint16 port)
{
return mTcpServer->listen(address, port);
}
void TcpConnectionDelegate::onReadyRead()
{
QTcpSocket * _client = (QTcpSocket *)(sender());
emit sigHasReadyClient(_client);
}
void TcpConnectionDelegate::onReadyForConnecting()
{
QTcpSocket * _client = mTcpServer->nextPendingConnection();
connect(_client, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
connect(_client, SIGNAL(disconnected()), _client, SLOT(deleteLater()));
// connect(_client, SIGNAL(destroyed(QObject *)), this, SLOT(onClientDestory(QObject *)));
}
void TcpConnectionDelegate::onAcceptError(QAbstractSocket::SocketError socketError)
{
LOGGING_LEVEL("debug")<<"@onAcceptError() "<<mTcpServer->errorString();
emit sigOnError(socketError);
}
void TcpConnectionDelegate::onClientDestory(QObject * obj)
{
// LOGGING_LEVEL("debug")<<"@onClientDestory() "<<obj;
}