Hi Arno, Thanks for the insight. More questions below:
Arno Garrels wrote: > Jake Traynham wrote: > >> So, it seems that for every time ASyncReceive looped, there would >> still be a message (FD_Read??) being put in the queue to call it >> again, which would call my DataAvailable event again, but there >> wouldn't be any data to read because ASyncReceive had already looped >> to get all the data. > > That's correct, it's the call to WSocket_Synchronized_ioctlsocket() > with option FIONREAD that causes winsock to send the extra FD_READ > message. > So nothing is corrupted, simply add wsoNoReceiveLoop to the options > to get rid of that behaviour. > Winsock will always send subsequent FD_Read messages after any call > to one of the receive functions if there is still data available. > Okay, so let me make sure I understand correctly. I call Receive in my DataAvailable event. If I don't request the entire amount of available data, winsock automatically throws another FD_Read message in the queue? So, that means that if I'm going to read in 1024 bytes at a time, I should set wsoNoReceiveLoop so that I don't get extra calls to DataAvailable. This makes sense and is what my code is currently doing. However, I would like this code to work/receive as fast as possible. The comment in the code where wsoNoReceiveLoop was introduced says that this option gives "lower resource usage with really fast LAN and large transfers". Does that mean it's faster, or just uses less memory? Would it be faster to read in all available data in each call to my DataAvailable event (which, if I understand correctly would not trigger the extra FD_Read events)? If so, what would be the best approach to that? Seems to me there would be three options: 1. Use GetRcvdCount to determine how much data Receive can return and read in that much data. (There is a comment in the code that says this function can't be trusted on NT....) 2. When I call Receive, specify a large enough buffer to read in whatever might be there. I'm currently using a 1024 byte buffer. Would increasing that to something over 1460 be sufficient? Or would winsock buffer the data in the background while I'm processing data and send me a chunk of data much larger than what can fit in an ethernet packet? 3. Put a loop in my DataAvailable event that will do a Receive until I get -1 back. This would probably be the easiest to implement for me. All in all, speed is my main interest here. I want to read in all the data the server is sending me as fast as possible. Thanks for any pointers you or anyone else on the list can give me. Jake -- Jake Traynham Owner, CNS Plug-ins http://www.cnsplug-ins.com/ -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be