Re: poll() returns even if there is data.

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

 



  On 07/22/2010 09:31 PM, Mansuri, Wasim (NSN - IN/Bangalore) wrote:
> I am trying to read some file using open and read system calls.
>
> Here in my code I am doing open than poll and if poll returns with the event POLLIN than read.
> Even if poll returns with the event POLLIN read returns 0, that means no data.
>
> My question here is,
> 	Am I using poll() properly?
> 	can we use poll to read the files like I am reading?
> 	If we can not use poll than is there any other way using which I can get to know if there is some data in the file after I did last read()?
>
> I am pasting code snip below.
> 	
>   if((fd = open(fileName,O_RDONLY))==-1){
>              printf("File opened Failed errno=%d\n",errno);
>              return (0);
>      }
>
>      loc = lseek(fd,0,SEEK_END);
>
>      fds[0].fd = fd;
>      fds[0].events = POLLIN;
>      fds[0].revents = 0;
>
>      while(1){
>          ret = poll(fds,1,timeout);
>          printf("poll returned with ret = %d, events = %d, revents=%d, errno =%d \n",ret,fds[0].events,fds[0].revents,errno);
>          if(fds[0].revents){
>              if((bytRcvd = read(fd,buff,1024))>0){
>                  printf("%s",buff);
>              }
>              else{
>                  printf("Read Failed on %s with retValue = %d Errno = %d \n",fileName, bytRcvd, errno);
>                  sleep(2);
>              }
>          }
>      }
>
> Above code always throws following output.
>
> poll returned with ret = 1, events = 1, revents=1, errno =0
> Read Failed on /var/log/messages with retValue = 0 Errno = 0

Sounds like you want to implement "tail -f" of sorts. If I'm not 
mistaken, you should use inotify for that, instead.


-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux