FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange segfault...

 
Post new topic   Reply to topic     Forum Index -> QtD
View previous topic :: View next topic  
Author Message
Mitu



Joined: 22 Sep 2009
Posts: 59
Location: Poland

PostPosted: Thu Jul 15, 2010 4:51 am    Post subject: Strange segfault... Reply with quote

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
View user's profile Send private message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Sun Jul 18, 2010 4:26 am    Post subject: Reply with quote

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
View user's profile Send private message
maxter



Joined: 17 May 2006
Posts: 34

PostPosted: Mon Jul 19, 2010 4:35 am    Post subject: Reply with quote

Fixed in http://www.dsource.org/projects/qtd/changeset/386%3A7dddafad5a20
Back to top
View user's profile Send private message
Mitu



Joined: 22 Sep 2009
Posts: 59
Location: Poland

PostPosted: Fri Jul 23, 2010 5:01 am    Post subject: Reply with quote

Thanks! It works now Smile

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 Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> QtD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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