Setting timeout for read api

S

Swaroop

PLS HELP..I am working on socket programming as part of my final year
project. I want to know how to set a timeout on read api that reads
from a socket. Is it possible using SIGALRM signal?Will setting
O_NONBLOCK flag of the socket help? Is there any other way to do it?
 
P

Paul Rubin

Swaroop said:
PLS HELP..I am working on socket programming as part of my final year
project. I want to know how to set a timeout on read api that reads
from a socket. Is it possible using SIGALRM signal?Will setting
O_NONBLOCK flag of the socket help? Is there any other way to do it?

You could do it with sigalrm but more common is to set a timeout on
the socket (see the settimeout method in the doc). You could also use
select with a timeout, and not read until the select tells you that
data is available.
 
D

David Schwartz

You could do it with sigalrm but more common is to set a timeout on
the socket (see the settimeout method in the doc). You could also use
select with a timeout, and not read until the select tells you that
data is available.

Just don't forget to set the socket non-blocking.

DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top