hey
I was practising with the QT programs, in one of my programs i created a thread and in the thread's execute statement i set the asynchronous socket mode but when i am recv it simply is blocking and is not freed unless i recv 2 connections.
should i use select call,though i do not need the client sockets or is there any other way to do the non blocking recv
any pointers please ...
#include "thread.h"
int sigflag=0;
void sigio_func(int i)
{
sigflag=1;
}
void mythread::run()
{
signal(SIGIO,sigio_func);
fcntl(0,F_SETOWN,getpid());
fcntl(0,F_SETFL,FASYNC);
int i=0;
//while(i<2)
{
int sock,bytes_rec,fromlen;
char buffer[65535];
struct sockaddr_in from;
struct ip* ipheader;
struct tcphdr *tcpheader;
char * buf;
sock = socket(AF_INET,SOCK_RAW,IPPROTO_TCP );
while(i<2)
{
sigblock(sigmask(SIGIO));
while(sigflag=0)
sigpause(0);
i++;
fromlen=sizeof(from);
bytes_rec = recv(sock,buffer,sizeof(buffer),0);
ipheader=(struct ip*)buffer;
tcpheader = ( struct tcphdr *)(buffer + (ipheader->ip_hl));
QString label1=inet_ntoa(ipheader->ip_src);
QListViewItem * item = new QListViewItem(tview,label1);
tview->insertItem(item);
sigflag=0;
sigsetmask(0);
}
}
}
void mythread::setList(QListView *view)
{
tview=view;
}