Re: Deaf CAsyncSocket on Windows Service.

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



See below...
On Tue, 20 Jan 2009 10:21:06 +0800, "Bill Brehm" <<don't want spam>> wrote:

Scott,

I think there is no way to find out before the Receive() call how much data
is waiting to be received, right? So I have to select an arbitrary buffer
size to read the data into. What happens if the amount of data I read out is
not all the data that's in their waiting to be read? Will I get a second
OnReceive() call for the data that came in already that I failed to read
out?
*****
Yes. You get an OnReceive notification if there is input data to be read. Why you have
concluded this has something to do with "packets" escapes me. It doesn't, and never did.
Packets are some uninteresting low-level implementation detail that is invisible to you.
****

My problem (in another branch of this thread) is that I seem to lose the
OnReceive() call rather than getting extra. I don't know if I am getting
extra calls (I will check this when i'm back at work soon) but if I am, they
would just break out with the WSAEWOULDBLOCK condition and cause no harm in
my case.

I will test with a single call to Receive() inside of OnReceive() and see if
the problem goes away. But I would like to understand why the error is
occurring.
*****
I'm not sure why the error is occurring, but the explanations you are suggesting are not
correct. There might be other reasons, but "packets arriving" have nothing to do with the
problem.
joe
******

Thanks,

Bill


"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
news:%23838bDpeJHA.3708@xxxxxxxxxxxxxxxxxxxxxxx

"Stephen Myers" <StephenMyers@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5E3F541A-A5B5-4B47-8651-BA120F86CD9E@xxxxxxxxxxxxxxxx
Is there any posibility that the data is being received but not
triggering
OnReceive()?

This can happen when two (or more) packets are received without a
Receive()
call. If you are doing the Receive() in as part of the OnReceive()
handling,
make sure there is no data left prior to exiting OnReceive().

Steve

On the contrary. Every call to Receive enables the message that will
produce the next call to OnReceive. It is therefore recommended that
Receive should be called only once per OnReceive notification. It is not
true that one must continue to call Receive until it would block.
(Reference: the MSDN page for WSAAsyncSelect - "an application need not
read all available data in response to an FD_READ message - a single recv
in response to each FD_READ message is appropriate.")

And, if Receive is called more than once in OnReceive there is a
possibility that another OnReceive notification message (FD_READ) is left
in the queue, and when it is processed later there will be no data.

Suggestion: Call Receive one time only per OnReceive, and make sure the
processing of received data does not permit the message pump to execute
until after you have returned from OnReceive. Both of these steps are
necessary to avoid the possibility of OnReceive and Receive getting out of
sync.

--
Scott McPhillips [VC++ MVP]

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Deaf CAsyncSocket on Windows Service.
    ... To read them out I need a buffer to ... the number of bytes waiting to be received. ... Perhaps the guy that said 'packets' should have said 'bytes of data' ... You get an OnReceive notification if there is input data to be read. ...
    (microsoft.public.vc.mfc)
  • Re: Custom Protocol
    ... Sent start message, waiting for response ... And you'd move between various states based on the packets you send. ... you mean a high level state. ...
    (comp.lang.ruby)
  • Re: Can anyone see this post?
    ... I suspect the I.P.s aren't to fast in handing off the packets. ... Yesterday I was waiting for a message I knew was transmitted at 10 am ...
    (microsoft.public.publisher)
  • Re: Losing UDP packets with MFC Sockets
    ... Receive you will pick up both packets in one buffer. ... >> Your receiving process does a Receive with a buffer of 100 bytes the ...
    (microsoft.public.vc.mfc)
  • Re: Deaf CAsyncSocket on Windows Service.
    ... Note that since you, at the application, have no idea how many packets are received, there ... the network stack to deal with the issues of reassembling a packet into a stream. ... how the receiver reassembles the input packets into a stream, ... Receive should be called only once per OnReceive notification. ...
    (microsoft.public.vc.mfc)