CAsyncSocket -> OnReceive -> Receive does not remove data in the queue?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Re: String Matching Problem
    ... Since several threads seem to be reading from the socket, ... may read another thread's answer which is why you need the buffer. ... worker threads so that each worker thread gets it's reply depends on ...
    (comp.lang.ruby)
  • Re: Discovering variable types...
    ... >memory it points to is on the heap. ... sequentially reading data, if one is randomly reading records, then a ... >project is what's prompting me to improve disk access. ... from a memory buffer I can do it in about a second. ...
    (comp.lang.pascal.delphi.misc)
  • Re: asrock, problem with nic after windows-boot - Exact Opposite issue the OP is having
    ... concerning Reading the Startup "Buffer" of the Bootup ... Time to read those startup scripts, ... are identified as STANDARD, INFORMATIONAL and HISTORIC, etc.? ...
    (comp.os.linux.networking)
  • Re: Yet Another Autoflush problem -- Whats wrong with this code?
    ... by reading in perlops that ... The sysread() call can potentially return anywhere -up- ... all guarantees about minimum I/O sizes are off: ... you will probably need to decrement your buffer size by the number ...
    (comp.lang.perl.misc)
  • Re: Memory Violation Copying Mesh Verticex buffer
    ... You are reading the mesh's vertices assuming they are as many as the ... a vertex buffer and an index buffer. ... >> float x, y, z; ... >>> What type of access violation do you get? ...
    (microsoft.public.win32.programmer.directx.graphics)