Re: CAsyncSocket -> OnReceive -> Receive does not remove data in the queue?
You may have more than one problem, because you are correct that calling
Receive should remove the data from the buffer. Are you checking the return
value from Receive? There is no guarantee that it will give you the byte
count that you asked for.
You must return from OnReceive before permitting any message pump to
operate, in order to avoid possible reentrancy into OnReceive. Instead of
directly creating other windows from OnReceive you can use
PostMessage(WM_APP+n,...) in OnReceive. Then the message handler for
WM_APP+n can do the followon processing that permits the message loop to
run.
"FFMG" <spambucket@myoddweb.com> wrote in message
news:7c77b9d5-842e-4e84-91ca-548d8b231fd1@o4g2000pra.googlegroups.com...
Hi,
I have data that is send from on socket to another.
As per the documentation, for every OnReceive( ... ) I call one Receive
( buffer, 4096 ) only.
I then handle the buffer of data, I read 8 bytes of data and that
tells me how many bytes I need to still read.
I then 'store' whatever bytes are left behind and on the next
'OnReceive( ... )' I add those bytes that were left over from the
previous operation and read the next 'batch' of 4096 bytes.
And I do that over and over again, hopefully all the data is in the
right order and everything should work out.
The problem is that some of the data I receive, by definition, cause
other windows or dialogs to appear and, because it has its own message
pump it causes another OnReceive( ... ) to be called _with the same
data_
In other words I am reading the same 4096 bytes again.
My understanding was that calling 'Receive( buffer, 4096 )' would
remove the data from the queue, making sure that it is only read once.
Obviously this causes problems when I am trying to unpack the data as
now everything is invalid.
What could be causing the problem, and more importantly, how do I
ensure that the data that I am reading is always new data and not data
that I have already read.
Simon
--
Scott McPhillips [VC++ MVP]