I'm doing some raw socket UDP send and receive. After establishing a UDP "connection" using connect()*, I use read() and write() on the client side to send/receive char data.
My client code works if I simply calls read in the following manner
So I am putting a timeout mechanism around it using alarm():Code:n = read(sd, recBuf, numBytes);
All of a sudden read() no longer works. I keep getting n = 0 bytes. I changed the server to send nothing and the timeout doesn't work either. The code return almost immediately with n = 0.Code:signal(SIGALRM, sig_alarm); alarm(5); n = read(sd, recBuf, numBytes); //handle errors here; Note: there exists a signal handler for SIGALRM alarm(0);
I don't get how setting a signal can affect descriptor operation... SOS
*UDP is connectionless. However, using connect() on UDP allows me to use read()/write() instead of sendto()/recvfrom().