Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a file descriptor has any data available?

Tags:

c

posix

I'd like to know if a fd has data available for reading. I have tried ioctl with FIONREAD but that results in a "Operation not supported error". Any ideas?

like image 413
StackedCrooked Avatar asked May 04 '10 09:05

StackedCrooked


2 Answers

You can use select(), with a zero (not NULL) timeout.

like image 162
unwind Avatar answered Oct 27 '22 01:10

unwind


Use poll() or select() on your file descriptor.

like image 43
bltxd Avatar answered Oct 27 '22 00:10

bltxd