bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TCPSession segfaults / hangs


From: Rami Saarinen
Subject: Re: TCPSession segfaults / hangs
Date: Sat, 20 Nov 2004 11:23:51 -0800 (PST)

Thanks David. That solves one problem and clears a lot of confusion. 

Does anyone have any ideas why the TCPListener seems to stall for minutes
after the first connection? I have made quite a lot of changes (not to the
TCPListener or TCPSessionThread classes) to the code so it just may work
better now, but I don't currently have a change to try it out. However,
none of the changes affect the TCP classes. So if any of you think of
anything that may give me a proper direction, I'd appreciate it.

And, while we're at it... What is the simplest and best way to get the IP
of the computer? Now it seems to make a hostname query to the DNS and
resolve the IP from it. That's not a problem as such, but has caused some
confusion earlier when one of the computers had a bit of DNS troubles. 

I promise I'll stop using you as my help-line for now on. :)  

--- David Sugar <address@hidden> wrote:

> In 1.2.x, you must use detach rather than start if you intend for your 
> thread to be a self deleting object, and you must exit the thread, and 
> NOT put a delete this in it's final; a detached thread, that is, started
> 
> by "detach" rather than "start", is automatically deleted when it exits
> now.

> 
> Rami Saarinen wrote:
[...]
> > TCPListener looks like this (mostly copied from the examples): 
> > ... 
> > void run() { 
> >   try { 
> >     TCPSessionThread<T> *tcp; 
> >     while(enabled) { 
> >         while(soc->isPendingConnection()) { 
> >           tcp = new TCPSessionThread<T>(*soc,this->master); 
> >           tcp->detach(); 
> >           //tcp->start();
> >         } 
> >     } 
> >   } catch(Socket *socket) { 
> > ... 
> >  
> > And TCPSessionThread is just as simple.. could do some work on the
> buffer
> > & data handling :) :  
> >  
> > ... 
> > void run() { 
> >   ssize_t val=1; 
> >   char buf[512]; 
> >   string *ret=new string();  
> >   while(val>0) { 
> >     val=readData((void *)buf,512); 
> >     string s(buf,val); 
> >     ret->append(s); 
> >     if(ret->size()>MAX_IN_BYTECOUNT) 
> >     throw OwnException("Buffer overrun in TCPSessionThread"); 
> >   } 
> >   ((T)this->master)->handleMessage(ret); 
> > } 
> >  
> > void final() { 
> >   delete this; 
> > } 
> >  
> > ... 
[...]

> > But on another laptop, where I need to get it to work, it does not
> work at
> > all. The setup is Fedora core 3 (gcc 3.4.2) and any version on ccpp2
> (from
> > 1.0.13 to 1.2.6).  
> >  
> > The problem seems to be TCPSession and especially the final() method
> of
> > it.  
> >  
> > 1. If I use older version of ccpp2, I get free() invalid pointer error
> > from glibc and the program aborts. If I comment out the delete this
> line
> > from final method. The program seg-faults (IIRC) 
> >  
> > 2. If I use ccpp2 1.2.6 I get the same free() invalid pointer error,
> but
> > if I comment out the "delete this" from the final method the
> TCPListener
> > seems to hang for minutes after the first TCPSession is created. After
> > several minutes the program continues and finally handles the pending
> > connections.  
> >  
> > I do use mutexes quite a lot, but they should not be the cause of the
> > lock-up/stall as the program works fine on other systems.  



                
__________________________________ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]