Commit bd22e08b authored by Thiago C. Santini's avatar Thiago C. Santini

Adds running state to network stream

As to not try to access the UDP socket after it has been deleted
parent f5792482
......@@ -11,6 +11,8 @@ NetworkStream::~NetworkStream()
void NetworkStream::onThreadStarted()
{
running = true;
if (settings.value("dataStream/transportProtocol").toString().compare("TCP", Qt::CaseInsensitive) == 0) {
tcpServer = new QTcpServer();
if (! listen() )
......@@ -19,18 +21,21 @@ void NetworkStream::onThreadStarted()
socket = new QUdpSocket(this);
socket->bind(QHostAddress(settings.value("dataStream/ip").toString()), settings.value("dataStream/port").toInt());
socket->connectToHost(QHostAddress(settings.value("dataStream/ip").toString()), settings.value("dataStream/port").toInt());
socket->setSocketOption(QAbstractSocket::LowDelayOption, 1);
}
}
void NetworkStream::onThreadFinishing()
{
running = false;
if (settings.value("dataStream/transportProtocol").toString().compare("TCP", Qt::CaseInsensitive) == 0) {
tcpServer->close();
tcpServer->deleteLater();
if (connected)
socket->deleteLater();
} else if (settings.value("dataStream/transportProtocol").toString().compare("UDP", Qt::CaseInsensitive) == 0) {
delete socket;
socket->deleteLater();
}
qDebug() << QThread::currentThread()->objectName() << " done.";
}
......@@ -62,7 +67,7 @@ void NetworkStream::closeSocket()
void NetworkStream::push(JournalEntry journalEntry)
{
if (!socket)
if (!running)
return;
if (settings.value("dataStream/transportProtocol").toString().compare("TCP", Qt::CaseInsensitive) == 0) {
......
......@@ -28,6 +28,7 @@ public slots:
QTcpServer *tcpServer;
QAbstractSocket *socket;
bool connected;
bool running;
bool listen();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment