[Qt-interest] Problem with FD_SET and select
Flavio Ceolin
flavio.ceolin at gmail.com
Fri Sep 18 13:56:03 CEST 2009
On Sep 18, 2009, at 3:30 AM, Thiago Macieira wrote:
> Em Sexta-feira 18. Setembro 2009, às 04.33.58, Flavio Ceolin escreveu:
>> void ThreadCommRead::run()
>> {
>> fd_set fds;
>> int aux=0;
>> FD_ZERO(&fds);
>> FD_SET(m_handle,&fds);
>> while(running){
>> aux = select(m_handle+1,&fds,NULL,NULL,&timer);
>> if(aux>0){
>> m_mutex->lock();
>> if((nbytes =
>> read(m_handle,buffer,BUFFERSIZE))>0)
>> emit dataRead(buffer,nbytes);
>> m_mutex->unlock();
>> }
>> }
>> }
>>
>
> Where is timer set? It has to be reset at every loop, because the
> select(2)
> call could modify it.
>
> According to the manual of select(2), it returns zero if the timer
> expires. It
> looks like that's what's happening in your example.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Senior Product Manager - Nokia, Qt Development Frameworks
> PGP/GPG: 0x6EF45358; fingerprint:
> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
>
> Qt Developer Days 2009 | Registration Now Open!
> Munich, Germany: Oct 12 - 14 San Francisco, California: Nov 2 - 4
> http://qt.nokia.com/qtdevdays2009
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
Hi Thiago,
timer is set on constructor of class, this is the code:
ThreadCommRead::ThreadCommRead(int handle,QObject* parent=
NULL,QMutex* mutex=NULL)
:QThread(parent)
{
m_handle = handle;
m_mutex = mutex;
timer.tv_sec = 2;
timer.tv_usec = 0;
}
Flavio Ceolin
skype: flavio.ceolin
msn: flavio.ceolin at hotmail.com
phone: +55 14 32276948
mobile: +55 13 97044877
flavio.ceolin at gmail.com
More information about the Qt-interest-old
mailing list