CAsyncSocket ::OnReceive() missed calls
-
I am developing a network application using CAsyncSocket. I have OnReceive() overridden to read data (as does everyone I guess!) All is fine - the application is successfully receiving data from the peer - until suddenly the calls to OnReceive() cease. For debugging, I also call ioctlsocket() with FIONREAD, and this reports that there are zero bytes in the network read buffer when the OnReceive() calls stop. However, if I force a new call to OnReceive() this proves that definitely IS data available - as more data is read. Also, calling AsyncSelect() when the stall occurs, DOES trigger a new call to OnReceive(). However I don't want to schedule calls to AsyncSelect() - I shouldn't have to - and that would cause a performance hit anyway. The stall occurs regularly - usually at least once every minute. An occasional missed call to OnReceive() would be tolerable, but this is ridiculous! There are similar issues noted on the internet, e.g. http://groups.google.co.uk/group/microsoft.public.vc.mfc/browse\_thread/thread/26f6d6cb0151c2ad/6ed6994c7bcdf45c?lnk=st&q=&rnum=3&hl=en#6ed6994c7bcdf45c .. but I have not seen a proper explanation, let alone resolution, and I have run out of things to try / debug. Any help very gratefully received! :confused:
cheers, Neil
-
I am developing a network application using CAsyncSocket. I have OnReceive() overridden to read data (as does everyone I guess!) All is fine - the application is successfully receiving data from the peer - until suddenly the calls to OnReceive() cease. For debugging, I also call ioctlsocket() with FIONREAD, and this reports that there are zero bytes in the network read buffer when the OnReceive() calls stop. However, if I force a new call to OnReceive() this proves that definitely IS data available - as more data is read. Also, calling AsyncSelect() when the stall occurs, DOES trigger a new call to OnReceive(). However I don't want to schedule calls to AsyncSelect() - I shouldn't have to - and that would cause a performance hit anyway. The stall occurs regularly - usually at least once every minute. An occasional missed call to OnReceive() would be tolerable, but this is ridiculous! There are similar issues noted on the internet, e.g. http://groups.google.co.uk/group/microsoft.public.vc.mfc/browse\_thread/thread/26f6d6cb0151c2ad/6ed6994c7bcdf45c?lnk=st&q=&rnum=3&hl=en#6ed6994c7bcdf45c .. but I have not seen a proper explanation, let alone resolution, and I have run out of things to try / debug. Any help very gratefully received! :confused:
cheers, Neil
-
I might be misremembering this, but doesn't there have to be a read pending before receive notifications are sent? (Normally I use raw sockets, or a custom class to manage TCP/UDP stuff, so my memory is a bit hazy on this one)
Steve S Developer for hire
Hi Steve Thanks for replying. I think a read IS pending. The problem is that the socket seems to "go to sleep" and it is necessary to call AsyncSelect() to make the framework realise data can be read. cheers, Neil
cheers, Neil
-
Hi Steve Thanks for replying. I think a read IS pending. The problem is that the socket seems to "go to sleep" and it is necessary to call AsyncSelect() to make the framework realise data can be read. cheers, Neil
cheers, Neil
-
I never came across this problem in my network applications. I wonder how your code in the OnReceive() handler looks like?
No, I think you are right. At the time I was using code from OpenSSL, and I think that causes some strange things to happen. I changed my algorithm, and now it is fully working. So I don't think there really is a bug with the MS software, you just have to be careful with these functions, and call them at the right times etc.
cheers, Neil