void CSocket
::connectToHost(const QString &hostName, quint16 port
) {
L_D(CSocket);
d->connectToHost(hostName, port);
}
void CSocketPrivate
::connectToHost(const QString &hostName, quint16 port
) {
}
void CSocketPrivate
::slotConnect(QString hostName, quint16 port
) {
m_wcConnected.wakeAll();
}
qint64 CSocket::send(const CTCPFrame &frame)
{
L_D(CSocket);
return d->send(frame);
}
qint64 CSocketPrivate::send(const CFrame &frame)
{
data = frame.serialize();
return send(data);;
}
qint64 CSocketPrivate
::send(const QByteArray &message
){
flush();
return Error;
}
void CLLSocketPrivate::slotReadyRead()
{
readTime->stop();
readBuffer();
readTime->start();
}
void CSocket::connectToHost(const QString &hostName, quint16 port)
{
L_D(CSocket);
QMutexLocker locker(&d->m_mMutex);
d->connectToHost(hostName, port);
}
void CSocketPrivate::connectToHost(const QString &hostName, quint16 port)
{
QTcpSocket::connectToHost(hostName, port);
}
void CSocketPrivate::slotConnect(QString hostName, quint16 port)
{
QMutexLocker locker(&m_mMutex);
QTcpSocket::connectToHost(hostName, port);
m_wcConnected.wakeAll();
}
qint64 CSocket::send(const CTCPFrame &frame)
{
L_D(CSocket);
QMutexLocker locker(&d->m_mMutex);
return d->send(frame);
}
qint64 CSocketPrivate::send(const CFrame &frame)
{
QByteArray data;
data = frame.serialize();
return send(data);;
}
qint64 CSocketPrivate::send(const QByteArray &message)
{
qint64 Error = QTcpSocket::write(message);
flush();
return Error;
}
void CLLSocketPrivate::slotReadyRead()
{
QMutexLocker locker(&m_mMutex);
readTime->stop();
readBuffer();
readTime->start();
}
To copy to clipboard, switch view to plain text mode
CSvrNetControlPrivate::CSvrNetControlPrivate(QPointer<QObject> parent, qint32 port, bool bIpv6) :
{
m_mMutex.lock();
m_Thread.start();
moveToThread(&m_Thread);
m_mMutex.unlock();
}
void CSvrNetControlPrivate::incomingConnection(int socketDescriptor)
{
newClient(socketDescriptor);
}
void CSvrNetControlPrivate::newClient(int socketDescriptor)
{
if (QThread::currentThread() != &m_Thread
) {
emit
signalNewClient(socketDescriptor);
if (!m_wcNewClientDone.wait(&m_mMutex, 10000))
{
qWarning() << "CSvrNetControl::newClient m_wcNewClientDone no triggered";
return;
}
}
else
{
makeNewClient(socketDescriptor);
}
}
void CSvrNetControlPrivate::slotNewClient(int socketDescriptor)
{
makeNewClient(socketDescriptor);
m_wcNewClientDone.wakeAll();
}
void CSvrNetControlPrivate::makeNewClient(int socketDescriptor)
{
QPointer<CSocket> socket = new CSocket(this);
if (!socket->setSocketDescriptor(socketDescriptor))
{
delete socket;
socket = 0;
return;
}
m_lSocket.append(socket);
connect(m_lSocket.last(), SIGNAL(disconnected()), this, SLOT(slotConnectionClosed()));
connect(m_lSocket.last(), SIGNAL(signalMessageReceived(CFrame)), this, SLOT(slotMessageReceived(CFrame)));
L_Q(CSvrNetControl);
emit q->signalNewClientConnected(m_lSocket.last()->peerAddress().toString());
}
void CSvrNetControl::broadcastMessage(const CFrame &frame)
{
L_D(CSvrNetControl);
return d->broadcastMessage(frame);
}
void CSvrNetControlPrivate::broadcastMessage(const CFrame &frame)
{
for (qint32 i = 0; i < m_lSocket.size(); i++)
{
sendMessagePrivate(m_lSocket.at(i), frame);
}
}
void CSvrNetControlPrivate::sendMessagePrivate(QPointer<CSocket> client, const CFrame &frame)
{
if ((QThread::currentThread() != &m_Thread
)) {
emit signalSend(client, frame);
if (!m_wcSended.wait(&m_mMutex, 10000))
{
qWarning
() <<
"CSvrNetControl::sendMessagePrivate m_wcSended no triggered" <<
QThread::currentThreadId();
m_eError = CErrorDescription(-1, "Not Performed");
}
}
else
{
sendMessage(client, frame);
}
}
void CSvrNetControlPrivate::slotSend(QPointer<CSocket> client, const CFrame &frame)
{
sendMessage(client, frame);
m_wcSended.wakeAll();
}
void CSvrNetControlPrivate::sendMessage(QPointer<CSocket> client, const CFrame &frame)
{
if (client)
{
client->send(frame);
}
}
CSvrNetControlPrivate::CSvrNetControlPrivate(QPointer<QObject> parent, qint32 port, bool bIpv6) :
QTcpServer(parent)
{
m_mMutex.lock();
m_Thread.start();
moveToThread(&m_Thread);
m_mMutex.unlock();
}
void CSvrNetControlPrivate::incomingConnection(int socketDescriptor)
{
QMutexLocker locker(&m_mMutex);
newClient(socketDescriptor);
}
void CSvrNetControlPrivate::newClient(int socketDescriptor)
{
if (QThread::currentThread() != &m_Thread)
{
emit
signalNewClient(socketDescriptor);
if (!m_wcNewClientDone.wait(&m_mMutex, 10000))
{
qWarning() << "CSvrNetControl::newClient m_wcNewClientDone no triggered";
return;
}
}
else
{
makeNewClient(socketDescriptor);
}
}
void CSvrNetControlPrivate::slotNewClient(int socketDescriptor)
{
QMutexLocker locker(&m_mMutex);
makeNewClient(socketDescriptor);
m_wcNewClientDone.wakeAll();
}
void CSvrNetControlPrivate::makeNewClient(int socketDescriptor)
{
QPointer<CSocket> socket = new CSocket(this);
if (!socket->setSocketDescriptor(socketDescriptor))
{
delete socket;
socket = 0;
return;
}
m_lSocket.append(socket);
connect(m_lSocket.last(), SIGNAL(disconnected()), this, SLOT(slotConnectionClosed()));
connect(m_lSocket.last(), SIGNAL(signalMessageReceived(CFrame)), this, SLOT(slotMessageReceived(CFrame)));
L_Q(CSvrNetControl);
emit q->signalNewClientConnected(m_lSocket.last()->peerAddress().toString());
}
void CSvrNetControl::broadcastMessage(const CFrame &frame)
{
L_D(CSvrNetControl);
QMutexLocker locker(&d->m_mMutex);
return d->broadcastMessage(frame);
}
void CSvrNetControlPrivate::broadcastMessage(const CFrame &frame)
{
for (qint32 i = 0; i < m_lSocket.size(); i++)
{
sendMessagePrivate(m_lSocket.at(i), frame);
}
}
void CSvrNetControlPrivate::sendMessagePrivate(QPointer<CSocket> client, const CFrame &frame)
{
if ((QThread::currentThread() != &m_Thread))
{
emit signalSend(client, frame);
if (!m_wcSended.wait(&m_mMutex, 10000))
{
qWarning() << "CSvrNetControl::sendMessagePrivate m_wcSended no triggered" << QThread::currentThreadId();
m_eError = CErrorDescription(-1, "Not Performed");
}
}
else
{
sendMessage(client, frame);
}
}
void CSvrNetControlPrivate::slotSend(QPointer<CSocket> client, const CFrame &frame)
{
QMutexLocker locker(&m_mMutex);
sendMessage(client, frame);
m_wcSended.wakeAll();
}
void CSvrNetControlPrivate::sendMessage(QPointer<CSocket> client, const CFrame &frame)
{
if (client)
{
client->send(frame);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks