Re: QTcpSocket deamon-thread
strange behaviour! can you post code?
1 Attachment(s)
Re: QTcpSocket deamon-thread
Here is code ilustrating the problem:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QHostAddress>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
static const int numOfSockets = 50;
int numOfProccessing;
public slots:
void onBtnStart();
};
#endif // MAINWINDOW_H
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->btnStart, SIGNAL(pressed()), this, SLOT(onBtnStart()));
for(int i = 0; i < MainWindow::numOfSockets; i++)
{
}
ui
->btnStart
->setText
(QString("Start(%1)").
arg(MainWindow
::numOfSockets));
hostAddress.setAddress("192.168.0.1");
}
MainWindow::~MainWindow()
{
for(int i = 0; i < MainWindow::numOfSockets; i++)
{
if(sockets[i].isOpen())
{
sockets[i].close();
}
}
delete ui;
}
void MainWindow::onBtnStart()
{
numOfProccessing = 0;
ui->btnStart->setEnabled(false);
for(int i = 0; i < MainWindow::numOfSockets; i++)
{
hostAddress.setAddress(hostAddress.toIPv4Address() + 1);
sockets[i].connectToHost(hostAddress, 2376);
qDebug
() <<
QString("connect to host %1").
arg(hostAddress.
toString());
numOfProccessing++;
}
}
{
ui->btnStart->setEnabled(--numOfProccessing == 0);
qDebug
() <<
QString("MainWindow::onError %1").
arg(e
);
}[ATTACH]6016[/ATTACH]
Added after 1 47 minutes:
It seems that these sockets exist even after app was closed. I used Wireshark to check if there is any traffic after sockets were deleted and it was. Can anybody tell me how to permanently and immediately close these sockets? QTcpSocket::abort() does not the trick.
Re: QTcpSocket deamon-thread
Hi mihau
I've just downloaded your code, looks like I can't reproduce this problem - after closing the app, all TCP traffic is gone ( checked with Wireshark as well, using Windows XP SP3 ).
How did you checked for the existence of daemon-thread ? For me (should say ProcessExplorer) it looks like all threads spawned by app are removed at exit.
Can you reproduce this behaviour on different machines ?
Re: QTcpSocket deamon-thread
I checked for thread existence in ProcessExplorer as well. I've tried to run this code on different machines and it seems to be machine dependent problem. Thanks for point out stampede.
Is it network driver fault? Any ideas?
Re: QTcpSocket deamon-thread
What "daemon thread" do you mean exactly? QTcpSocket doesn't spawn any external processes. Nor threads, for that matter.
Re: QTcpSocket deamon-thread
"Daemon thread" is just an expression. I don't know exacly what is happening. On some machines one thread lasts even after application was closed and network traffic is still present. It seems that these sockets still exist in system. In some cases this situation can lead to bluescreen!
Re: QTcpSocket deamon-thread
Quote:
Originally Posted by
mihau
"Daemon thread" is just an expression.
Well, if you didn't know the road traffic rules and somebody told you that you should walk into the road when the red light is on and when you do that and get ran over by a car, I don't think you'd agree that "walk into the road when the red light is on" was just an expression.
Quote:
On some machines one thread lasts even after application was closed and network traffic is still present. It seems that these sockets still exist in system. In some cases this situation can lead to bluescreen!
Do you mean 'thread' or 'just-an-expression-thread'? What lasts where? Could you be more specific?
Re: QTcpSocket deamon-thread
A process (including one thread) exists in ProcessExplorer after app was closed. When network traffic is over this process disapears. I've tested it on several machines (all with Win XP) and this behaviour could not be reproduced on every one.