View previous topic :: View next topic |
Author |
Message |
Mitu
Joined: 22 Sep 2009 Posts: 59 Location: Poland
|
Posted: Thu Jul 15, 2010 4:51 am Post subject: Strange segfault... |
|
|
Hello.
I'm trying to get rid of strange segfault connected with threads and QSslSocket.
The problem started to occur after switching to KDE 4.5 and reinstallig QtD. I have DMD 2.047. (No code changes have been made!)
The thing I want to create is a pinging thread. It's a part of larger project, so putting all the source isn't a good idea. Instead of it I created a smaller example, where the problem also occurs:
Code: | import core.thread;
import qt.core.QByteArray;
import qt.core.QObject;
import qt.gui.QApplication;
import qt.network.QSslError;
import qt.network.QSslSocket;
// Solving names conflicts
alias std.string.startsWith startsWith;
class GaduConnection : QObject
{
QSslSocket socket;
string host;
ushort port;
Thread pinger;
synchronized bool continuePinging;
this(string host, ushort port)
{
this.host = host;
this.port = port;
socket = new QSslSocket();
pinger = new Thread(&this.sendPing);
}
void connectToServer()
{
connect(socket, "encrypted", this, "go");
socket.connectToHostEncrypted(host, port);
}
void sendPing()
{
continuePinging = true;
while(continuePinging)
{
scope byte[] headerData = [8, 0, 0, 0, 0, 0, 0, 0];
QByteArray byteArray = new QByteArray();
foreach(byte b; headerData)
{
byteArray.append(b);
}
std.stdio.writeln("1 ", socket.isEncrypted());
socket.write(byteArray); // SEGFAULT
std.stdio.writeln("2");
pinger.sleep(1_0000000);
std.stdio.writeln("3");
}
}
void slot_go()
{
std.stdio.writeln("Go!");
pinger.start();
}
mixin Q_OBJECT;
}
void main(string[] args)
{
QApplication app = new QApplication(args);
GaduConnection c = new GaduConnection("ggproxy-26.gadu-gadu.pl", 443);
c.connectToServer();
app.exec();
} |
To build:
Code: | $ dmd main.d -L-lqtdcore -L-lQtCore -L-lQtNetwork -L-lqtdnetwork -L-lcpp_core -L-lcpp_network -L-lqtdgui -L-lQtGui -L-lcpp_gui |
In the whole project segfault appers also on "pinger.sleep()", but in this example suprisingly thread sleeps fine...
If anyone could help me I would be grateful, I have no idea what to do with this... |
|
Back to top |
|
|
maxter
Joined: 17 May 2006 Posts: 34
|
Posted: Sun Jul 18, 2010 4:26 am Post subject: |
|
|
I've reproduced the bug. Will try to fix it soon.
Thank you for taking time to report QtD problems. It would be great if you post bug reports as tickets in the future. |
|
Back to top |
|
|
maxter
Joined: 17 May 2006 Posts: 34
|
|
Back to top |
|
|
Mitu
Joined: 22 Sep 2009 Posts: 59 Location: Poland
|
Posted: Fri Jul 23, 2010 5:01 am Post subject: |
|
|
Thanks! It works now
I had no idea it could be an error in QtD, I just thought I've messed up something with the threads and hoped to get help here.
Thanks again! When I'll catch anu bug in QtD, I'll post an issue |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|