Click to See Complete Forum and Search --> : How do I know when there's data available...
How do I know when there's data available in a socket's buffer?
I'm using a CSocket object and haven't created my own derived class. And I need to know at any given time how I can tell if there's data to read in the socket's buffer. Actually I want to poll the socket for incoming data...how do I go about this?
Thanks.
June 10th, 1999, 03:32 AM
What is so difficult about this question?
>>How do I know when there's data available in a socket's buffer?
Somebody must know how or think they have a clue or something...
Thanks again.
Dave Lorde
June 10th, 1999, 06:50 AM
It's all there in the online docs. Check out the Receive() and OnReceive() members of CAsyncSocket, the base class of CSocket.
Dave
June 10th, 1999, 07:21 AM
Hi Dave,
Thank you for pointing that out. Clearly you haven't read the original question. It follows:
>>I'm using a CSocket object and haven't created my own derived class. And I
>>need to know at any given time how I can tell if there's data to read in the
>>socket's buffer. Actually I want to poll the socket for incoming data...how
>>do I go about this?
When you don't have a derived socket class, how can you know if there's data in a given socket's buffer?
Hope that explains it.
Thanks.
Dave Lorde
June 10th, 1999, 08:01 AM
I read your original message. I thought you might decide to use CSocket as it was intended to be used, and save yourself some time and effort.
However if you really want to reinvent the wheel, you can duplicate what CSocket does to generate the OnReceive() notification, which is to handle the WM_SOCKET_NOTIFY message looking for an FD_READ event code in lparam.
If you want to poll the socket, you'll have to ask someone else.
Hope that explains it.
Dave
Jason Teagle
June 10th, 1999, 09:10 AM
Clearly you did not read the help file for CSocket and CAsyncSocket thoroughly enough before getting crabby with people trying to help you. If you had done so, you would have found that a call to CAsyncSocket::IOCtl() can set the socket to non-blocking, and then calls to Receive() would return immediately with a code to indicate that there is no data currently, which would have resulted in a blocking call if it had been performed. If there was data, it would read it and return the number of bytes read. Therefore, you could use CAsyncSocket for your needs, and just switch between blocking and non-blocking as necessary. IOCtl() may even work on CSocket and Receive() would subsequently return the same error code rather than block, although I can't be bothered to check.
If you are going to ask people for help on this BB, please have the courtesy to be polite, even if they make a mistake - you can still point out their mistake without getting rude.
June 10th, 1999, 09:42 AM
Hi,
Sorry about getting a little pissed, but after loosing much sleep about it I got very irritated. My apologies to you sir, and everyone on this board.
After re-reading the help I think that I will take Jason's advice.
Thanks again.
Dave Lorde
June 11th, 1999, 04:08 AM
Apology accepted, no harm done. I know what it's like - things always look worse after you post them than you intend when you write them :-)
Dave
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.