style: update code style

This commit is contained in:
Qsaker 2024-01-25 23:13:13 +08:00
parent 5f9b205d67
commit 9abc5385cb
2 changed files with 24 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/*************************************************************************************************** /***************************************************************************************************
* Copyright 2023 Qsaker(qsaker@foxmail.com). All rights reserved. * Copyright 2023-2024 Qsaker(qsaker@foxmail.com). All rights reserved.
* *
* The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project. * The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project.
* *
@ -17,29 +17,29 @@ SAKUdpServerTool::SAKUdpServerTool(QObject *parent)
bool SAKUdpServerTool::initialize(QString &errStr) bool SAKUdpServerTool::initialize(QString &errStr)
{ {
mUdpSocket = new QUdpSocket(); m_udpSocket = new QUdpSocket();
bool ret = false; bool ret = false;
if (mSpecifyIpAndPort) { if (mSpecifyIpAndPort) {
ret = mUdpSocket->bind(QHostAddress(mServerIp), mServerPort); ret = m_udpSocket->bind(QHostAddress(mServerIp), mServerPort);
} else { } else {
ret = mUdpSocket->bind(); ret = m_udpSocket->bind();
} }
if (!ret) { if (!ret) {
//outputMessage(QtWarningMsg, mUdpSocket->errorString()); qWarning() << m_udpSocket->errorString();
errStr = mUdpSocket->errorString(); errStr = m_udpSocket->errorString();
return false; return false;
} }
QString ip = mUdpSocket->localAddress().toString(); QString ip = m_udpSocket->localAddress().toString();
int port = mUdpSocket->localPort(); int port = m_udpSocket->localPort();
mBindingIpPort = QString("%1:%2").arg(ip).arg(port); mBindingIpPort = QString("%1:%2").arg(ip).arg(port);
//outputMessage(QtInfoMsg, mBindingIpPort); qInfo() << mBindingIpPort;
emit bindingIpPortChanged(); emit bindingIpPortChanged();
connect(mUdpSocket, &QUdpSocket::readyRead, mUdpSocket, [=]() { readBytes(); }); connect(m_udpSocket, &QUdpSocket::readyRead, m_udpSocket, [=]() { readBytes(); });
connect(mUdpSocket, SAK_SIG_SOCKETERROROCCURRED, this, [=]() { connect(m_udpSocket, SAK_SIG_SOCKETERROROCCURRED, this, [=]() {
emit errorOccurred(mUdpSocket->errorString()); emit errorOccurred(m_udpSocket->errorString());
}); });
return true; return true;
@ -65,14 +65,14 @@ void SAKUdpServerTool::writeBytes(const QByteArray &bytes)
void SAKUdpServerTool::uninitialize() void SAKUdpServerTool::uninitialize()
{ {
mUdpSocket->deleteLater(); m_udpSocket->deleteLater();
mUdpSocket = nullptr; m_udpSocket = nullptr;
} }
void SAKUdpServerTool::readBytes() void SAKUdpServerTool::readBytes()
{ {
while (mUdpSocket->hasPendingDatagrams()) { while (m_udpSocket->hasPendingDatagrams()) {
auto len = mUdpSocket->pendingDatagramSize(); auto len = m_udpSocket->pendingDatagramSize();
if (len == -1) { if (len == -1) {
break; break;
} }
@ -80,9 +80,9 @@ void SAKUdpServerTool::readBytes()
QByteArray bytes(len, 0); QByteArray bytes(len, 0);
QHostAddress address; QHostAddress address;
quint16 port; quint16 port;
qint64 ret = mUdpSocket->readDatagram(bytes.data(), bytes.length(), &address, &port); qint64 ret = m_udpSocket->readDatagram(bytes.data(), bytes.length(), &address, &port);
if (ret == -1) { if (ret == -1) {
//outputMessage(QtWarningMsg, mUdpSocket->errorString()); qWarning() << m_udpSocket->errorString();
break; break;
} }
@ -90,7 +90,7 @@ void SAKUdpServerTool::readBytes()
QString hex = QString::fromLatin1(ba); QString hex = QString::fromLatin1(ba);
QString info = QString("%1:%2").arg(address.toString()).arg(port); QString info = QString("%1:%2").arg(address.toString()).arg(port);
QString msg = QString("%1<-%2:%3").arg(mBindingIpPort, info, hex); QString msg = QString("%1<-%2:%3").arg(mBindingIpPort, info, hex);
//outputMessage(QtInfoMsg, msg); qInfo() << msg;
if (!mClients.contains(info)) { if (!mClients.contains(info)) {
mClients.append(info); mClients.append(info);
@ -106,12 +106,12 @@ void SAKUdpServerTool::writeDatagram(const QByteArray &bytes,
const QString &ip, const QString &ip,
quint16 port) quint16 port)
{ {
qint64 ret = mUdpSocket->writeDatagram(bytes, QHostAddress(ip), port); qint64 ret = m_udpSocket->writeDatagram(bytes, QHostAddress(ip), port);
if (ret == -1) { if (ret == -1) {
//outputMessage(QtWarningMsg, mUdpSocket->errorString()); qWarning() << m_udpSocket->errorString();
} else { } else {
QString hex = QString::fromLatin1(SAKInterface::arrayToHex(bytes, ' ')); QString hex = QString::fromLatin1(SAKInterface::arrayToHex(bytes, ' '));
//outputMessage(QtInfoMsg, QString("%1<-%2").arg(mBindingIpPort, hex)); qInfo() << QString("%1<-%2").arg(mBindingIpPort, hex);
emit bytesWritten(bytes, mBindingIpPort); emit bytesWritten(bytes, mBindingIpPort);
} }
} }

View File

@ -1,5 +1,5 @@
/*************************************************************************************************** /***************************************************************************************************
* Copyright 2023 Qsaker(qsaker@foxmail.com). All rights reserved. * Copyright 2023-2024 Qsaker(qsaker@foxmail.com). All rights reserved.
* *
* The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project. * The file is encoded using "utf8 with bom", it is a part of QtSwissArmyKnife project.
* *
@ -25,7 +25,7 @@ protected:
void readBytes(); void readBytes();
private: private:
QUdpSocket *mUdpSocket{nullptr}; QUdpSocket *m_udpSocket{nullptr};
private: private:
void writeDatagram(const QByteArray &bytes, const QString &ip, quint16 port); void writeDatagram(const QByteArray &bytes, const QString &ip, quint16 port);