marcoo
asked on
read()
Hi there i'm working with a mail client in linux.
My problem is : when i use the func read to read from the socket it prompts until data arrives so if
no data arrives it just prompts forever. I wonder if there is a possibility to abort it after sometime or with another function??
My problem is : when i use the func read to read from the socket it prompts until data arrives so if
no data arrives it just prompts forever. I wonder if there is a possibility to abort it after sometime or with another function??
To deal with socket, you'd rather use send() and recv() instead of write() and read(), to gain greater control over data transmission. For a guide for start, take a look at http://www.ecst.csuchico.edu/~beej/guide/net/
Use the select system call. It allows you to specify for what time you want to monitor a number of file descriptors. It is very good for monitoring a no. of fds, including sockets, at the same time.
Specify your socket fd as the one to monitor for reading in select() alongwith the timeout. When the select call returns, check its reason for return i.e. data has arrived or timeout occurred. U can then read data from socket accordingly.
Specify your socket fd as the one to monitor for reading in select() alongwith the timeout. When the select call returns, check its reason for return i.e. data has arrived or timeout occurred. U can then read data from socket accordingly.
ASKER
Ehh.. i don't quite understand do you think you can give me an example??
I'd appreciate it Marcoo..
I'd appreciate it Marcoo..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK thanx i'll will try it out..