LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2008, 12:35 AM   #1
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Rep: Reputation: 24
Unhappy problem with the POLLHUP revent


Hello Friends,

I have 2 progs, client.c and server.c

I am having a strange problem with my polling function in server program.

The server program contains a function, that is polling on a file descriptor. When poll() syscall detects data to be read on descriptor, I am getting POLLIN in revent.

Now, at last the client closes the socket, at tht time the poll() syscall should give me the POLLHUP in revents. Now, here is the problem, instead of giving me the POLLHUP it continuously giving me the POLLIN revent, so my program goes into infinite loop and CPU usage goes higher and higher.

I have tried to make socket readonly using fcntl(), but I can not get satisfactory results.

Here is the part of code....
Code:
void my_poll()
{
        int poll_ret=0,temp=0,len=0;

        for(;;)
        {
                poll_ret = poll(array_fd,2,1000); //struct pollfd array_fd[2]; 1000 milisec timeout

                if(poll_ret > 0)
                {
                        for(temp = 0;temp < 2;temp++)
                        {
                                if((array_fd[temp].revents & POLLHUP))
                                {
					//at the time of client socket close, I am not reaching here
                                        printf("Got POLLHUP revent. Client has closed the socket");
					close(array_fd[temp]);
                                        array_fd[temp].fd =-1;
                                        poll_ret--;
                                        if(poll_ret <= 0)
                                                break;
                                }

                                if(array_fd[temp].revents & POLLIN)
                                {
                                        char buff[255];
					//I am getting this revent, and I can read the data
                                        printf("Got POLLIN revent, Now going to read the data...\n");

                                        if( (len = recv( array_fd[temp].fd, buff,sizeof(buff),0)) > 0)
                                        {
                                                printf("Len Of Recv bytes %d \n",len);
                                        }
                                                   
                                        poll_ret--; 
                                        if(poll_ret <= 0)
                                                break;
                                }//if over
                        }//for over
                }//if over
        }//for over
}//end of function
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration