questions about non-blocking read()


 
Thread Tools Search this Thread
Top Forums Programming questions about non-blocking read()
# 1  
Old 05-23-2007
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!
# 2  
Old 05-23-2007
Is this what you were looking for?
http://beej.us/guide/bgnet/output/ht....html#blocking
# 3  
Old 05-24-2007
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 )
}
# 4  
Old 05-24-2007
Hey thanks for the replies.
It really helps
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Which are blocking and non-blocking api's in sockets in C ?

among the below socket programming api's, please let me know which are blocking and non-blocking. socket accept bind listen write read close (2 Replies)
Discussion started by: VSSajjan
2 Replies

2. Homework & Coursework Questions

Print questions from a questions folder in a sequential order

1.) I am to write scripts that will be phasetest folder in the home directory. 2.) The folder should have a set-up,phase and display files I have written a small script which i used to check for the existing users and their password. What I need help with: I have a set of questions in a... (19 Replies)
Discussion started by: moraks007
19 Replies

3. UNIX for Dummies Questions & Answers

Blocking signals

I know how to add signal to a set. But what if I want to add 2 or 3 signals to the set. I know I can use sigaddset (&set,SIGBUS)....but what if I want to add SIGBUS and SIGALRM at once. Do i have to do it like this.. sigaddset (&set,SIGBUS); sigaddset (&set,SIGALRM); Is there another way to... (0 Replies)
Discussion started by: joker40
0 Replies

4. Programming

non blocking connect

OS : solaris 10 X86 I created stream socket, tries to connect to port 7 on the remote machine. After doing the non blocking connect call I did select with time out value is 3 secs. I am always getting timed out though I am writing prior to select. code: x=fcntl(S,F_GETFL,0);... (1 Reply)
Discussion started by: satish@123
1 Replies

5. UNIX for Advanced & Expert Users

ps blocking

Hi Folks I have been debugging a script that is called every thirty seconds. Basically it is doing a ps, well two actually, one to file (read by the getline below) and the other into a pipe. The one into the pipe is: - V_SYSVPS=/usr/sysv/bin/ps $V_SYSVPS -p$PIDLIST -o$PSARGS... (0 Replies)
Discussion started by: steadyonabix
0 Replies

6. UNIX for Dummies Questions & Answers

Permission file questions--Please read!!!

1. I have an executable file that I have granted the users full permission "777" for it to work. I don't want the user to read this file! How can I prevent a user to read it? Thanks (4 Replies)
Discussion started by: bobo
4 Replies

7. Programming

Blocking file read

There are many processes writing to log files at random times (they are all programmed in different manners and can not be altered). I am writing a new c program which should read from the log files whenever they are updated. At the moment it is just spooling, waiting for a change in file size, but... (2 Replies)
Discussion started by: cubathy
2 Replies

8. UNIX for Dummies Questions & Answers

Blocking a Single IP

Hello, My problem thus follows: I am running a server which allows users to connect on UDP, not TCP. There is a certain hacker, whom I have the IP of, who keeps crashing the server. I simply want to block him from accessing my box at all. I added him to the hosts.deny file, but am not sure if... (4 Replies)
Discussion started by: Phobos
4 Replies

9. IP Networking

blocking DHCP

I've got a legit DHCP server on my network. I've got a 3550 as my VTP server providing 4 vlans to 4 2950 switches. If somebody were to plug into one of those vlans with a DHCP server configured then it would throw off my whole network. How could i block the DHCP server that could plug into the... (2 Replies)
Discussion started by: byblyk
2 Replies

10. UNIX for Dummies Questions & Answers

blocking domains

Dear All , Kindly note I have sun solaries 7 . I want to block a domain who keep sending emails to my domain and users . thanks (1 Reply)
Discussion started by: tamemi
1 Replies
Login or Register to Ask a Question