Linux: RedHat enterprise: C, read() & select() not blocking
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Linux: RedHat enterprise: C, read() & select() not blocking




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Linux: RedHat enterprise: C, read() & select() not blocking  
karres@uiuc.edu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

Hi,

I think this should be simple.  I thaink I have done something similar
a long time ago but the magic is hiding from me.

I have a system log file that grows and is rotated once a month.  I
need to read the whole log file once then "hang" on the bottom of the
file waiting for more input.

Eventually the file will be rotated.  I want to have read every spec of
data in the now old log; close it and then open the new log and start
from the top.

I figured that setting up a select() then doing the read() would work.
However, the select is not blocking at all.  My test file is zero
length in this test.  I open the file, do the select and it returnes
immediately saying that the descriptor on that zero length file is
ready for reading... huh?

I then read zero bytes form the file and repeat... forever.

I assumed that the select would block on the zero length file until
something was sent to it.

I am FD_ZEROing, FD_SETing and reseting the time struct before each
select call

while (1)
{
FD_ZERO (&read_FDs);
FD_SET (file_no, &read_FDs);

select_timeout.tv_sec = 60;     /* 1 minute, why not? */
select_timeout.tv_usec = 0;

if ((select_result = select ((file_no + 1), &read_FDs,
NULL, NULL, &select_timeout)) > 0)
{
if (FD_ISSET (WTMP_file_no, &read_FDs))
{
if ((read_result = read (file_no, &wtmp,
size_of_buf)) > 0)
{
...process read...
}
else if (read_result == 0)
{
/*
* read zero bytes on what should have been a
* prepared stream.
*/
}
else
{
exit (__LINE__);
}
}
else
{
/*
* select says there is pending data but the FD is not
* set.  what gives?
*/
exit (__LINE__);
}
}
else if (select_result == -1)
{
exit (__LINE__);
}
}

I am opening the file read-only

file_no = open (file, O_CREAT | O_RDONLY, 0664)

Obviously I am missing something in the select() man page.  What am I
missing?

Dean...K...






[ Post a follow-up to this message ]



    Re: Linux: RedHat enterprise: C, read() & select() not blocking  
Barry Margolin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

In article <1103177363.287358.58530@c13g2000cwb.googlegroups.com>,
karres@uiuc.edu wrote:
> I assumed that the select would block on the zero length file until
> something was sent to it.

No, select() will never block on a normal file.  Select() tells you
whether read() would have blocked.  Since read() will always return
immediately (ignoring NFS delays), either with data or an EOF
indication, select() should always report it being readable.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***





[ Post a follow-up to this message ]



    Re: Linux: RedHat enterprise: C, read() & select() not blocking  
karres@uiuc.edu


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-17-04 12:45 AM

Ah!  ok.  thank you






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:59 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register