Pag Posted January 5, 2007 Share Posted January 5, 2007 Hy! Is there a way to define a timeout for the recv function? AFAIK, recv(sock,buffer,256,0); would wait for data FOREVER which is a big problem if the connection to the AP is lost... thx Link to comment Share on other sites More sharing options...
amunra Posted January 12, 2007 Share Posted January 12, 2007 Hy! Is there a way to define a timeout for the recv function? AFAIK, recv(sock,buffer,256,0); would wait for data FOREVER which is a big problem if the connection to the AP is lost... thx Hi all, I have got the same problem here. I have added some trace to my code and this is what I have so far.. * calling recv() after opening the socket and before any other network IO works fine. The recv() funciton does not block and functions as expected.* After I call send() I receive a load of data. Again this works as expected.* when the incomming data ends the recv() function hangs on the first call expected to return EWOULDBLOCK. I have tryed using: flag = fcntl( *psocket, F_GETFL, 0 );fcntl( *psocket, F_SETFL, flag | O_NONBLOCK ); and bytes_read = recv( p->stream_sockets[socket_id].socket, (char*)data, data_sz, MSG_PEEK ) but neither of these make any difference. If the socket is closed by the server while the recv() funtion is hung it still does not return. This implies to me that the recv() function has either crashed or entered an endless loop. I have a 100% repeatable situation and I am happy to help find this bug... Cheers Amun-Ra Link to comment Share on other sites More sharing options...
amunra Posted January 12, 2007 Share Posted January 12, 2007 Hy! Is there a way to define a timeout for the recv function? AFAIK, recv(sock,buffer,256,0); would wait for data FOREVER which is a big problem if the connection to the AP is lost... thx Hi all, I have got the same problem here. I have added some trace to my code and this is what I have so far.. * calling recv() after opening the socket and before any other network IO works fine. The recv() funciton does not block and functions as expected.* After I call send() I receive a load of data. Again this works as expected.* when the incomming data ends the recv() function hangs on the first call expected to return EWOULDBLOCK. I have tryed using: flag = fcntl( *psocket, F_GETFL, 0 );fcntl( *psocket, F_SETFL, flag | O_NONBLOCK ); and bytes_read = recv( p->stream_sockets[socket_id].socket, (char*)data, data_sz, MSG_PEEK ) but neither of these make any difference. If the socket is closed by the server while the recv() funtion is hung it still does not return. This implies to me that the recv() function has either crashed or entered an endless loop. I have a 100% repeatable situation and I am happy to help find this bug... Cheers Amun-Ra Hi all, I have managed to create a workaround for this. I downloaded the 0.3c source code and traced the hang into sgIP_sockets.c line 178. It never exits that loop. According to the recv() man page when using the MSG_PEEK flag recv() should not block. So I added the following line just under the sgIP_TCP_Recv() call: if(retval==-1&&flags&MSG_PEEK) retval=0; This makes the recv() function exit with zero bytes when there is nothing to retrieve and the MSG_PEEK flag is set. Then my app can use this flag to see if there is data to get before it calls recieve. This has worked a treat and I hope this fix is intergrated into the next version of the dswifi lib. I also noted this line in the same loop:if(socketlist[socket].flags&SGIP_SOCKET_FLAG_NONBLOCKING) break; But for some reson this condition was not working. Yet as I explained in my previous post it did work when the socket was first opened. I beleive this flag is somehow being reset. This is the real bug all I have done is fixed the MSG_PEEK bug to enable a workaround. Cheers Amunra Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now