The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Permission file questions--Please read!!! bobo UNIX for Dummies Questions & Answers 4 02-10-2007 08:03 PM
Blocking file read cubathy High Level Programming 2 07-01-2006 05:28 AM
blocking DHCP byblyk IP Networking 2 03-15-2005 09:06 PM
School Blocking Satine IP Networking 1 02-07-2005 02:07 PM
blocking domains tamemi UNIX for Dummies Questions & Answers 1 04-16-2003 04:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2007
Registered User
 

Join Date: May 2007
Posts: 2
questions about non-blocking read()

Hi,

I need to read incoming data from a serial port. I also need the read() to be non-blocking, such that my program can then check for any data to be send via the serial port. I followed some FAQs on the net, set read() to be non-blocking, and got EAGAIN errors popping out.

I realise that under non-blocking mode, it is normal to receive EAGAIN errors. Thus, the next thing I did, is try using select().

Is select() also blocking? How do I use select()?
Can someone provide me some codes or any directions to get started on select()?

Thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 05-23-2007
Registered User
 

Join Date: Feb 2007
Posts: 67
Is this what you were looking for?
http://beej.us/guide/bgnet/output/ht....html#blocking
Reply With Quote
  #3  
Old 05-23-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Quote:
Originally Posted by oddabe
How do I use select()?
Select lets the system efficiently wait for events on a number of file descriptors or else timeout. Any X application has select as the call that is executed when the application has nothing to do.

There are three sets of filedescriptors, those for reading, those for writing and those for exceptional conditions, a file descriptor may be in multiple sets.

When you get EGAIN or EWOULDBLOCK use select to tell you when the filedescriptor is ready again.

fd_set fds;
FD_ZERO(&fds);
FD_SET(fd,&fds);
i=select(fd+1,&fds,NULL,NULL,NULL);
if (i>0)
{
if (FD_ISSET(fd,&fds)) { do your thing )
}
Reply With Quote
  #4  
Old 05-23-2007
Registered User
 

Join Date: May 2007
Posts: 2
Hey thanks for the replies.
It really helps
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0