Re: CSocket, best way to wait for a reply?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Been there, done that. Actually, didn't do that. The failure I mentioned earlier was
someone trying to implement this. It was a first-order total disaster. I had looked at a
few lines of code and said "under load, you lose packets, you send the wrong response to a
client, and eventually the whole system locks up". I said this by looking at ONE SCREENFUL
of their code, which had at least six major design errors in it, and it took me under a
minute to arrive at this conclusion. They had tried to retrofit asynchronous sockets into
a synchronous-socket program, and done it so badly it was unbelievable.

WIshing something would exist, when that something works in direct contravention to common
sense, isn't productive. As soon as you stop thinking that everything has to be
synchronous, your life gets easier.

Note that most windows functions are synchronous because there is not actually any
significant delay. And note that those which can have delay, such as I/O, actually have
asynchronous models for very good reasons. Most of us don't notice when our ReadFile takes
an extra 10ms because a head seek is involved, but if you are trying to process 100K TPM
(transactions per minute) you can't live with those 10ms delays. In networking, delays of
tens of seconds can be expected. Timeouts consequently need to be very large (the extreme
case is DNS resolution, which can take up to 70 seconds).
joe

On Fri, 08 Apr 2005 15:55:07 GMT, "AliR" <AliR@xxxxxxxxxxxxxxxx> wrote:

>I have a question, Isn't the majority of windows functions synchronous in
>nature? You ask the system to do something by calling a function and when
>the function returns it's done!
>
>Why can't there be a function that uses CAsyncSocket to do some kinda
>communication that does not return until there is a response or a timeout is
>reached?
>
>AliR.
>
>"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message
>news:O61IkODPFHA.4000@xxxxxxxxxxxxxxxxxxxxxxx
>> simon wrote:
>> >>Did you remove all the unnecessary message looping? I have several
>> >>applications that work flawlessly using CAsyncSocket the way it was
>> >>designed to be used (i.e. by simply overriding the virtual functions).
>> >>
>> >
>> >
>> > I have to an extent, the client still waits for a reply from the server
>but
>> > does not block the whole system anymore.
>> > ideally I would remove the need for waiting for a reply within the same
>> > function, but that would mean a lot of re-engineering.
>> >
>> > I wish there was a simple. safe, way to send/receive data between
>sockets in
>> > one call.
>> > If I 'ask' a question to the server how else would I wait for my reply.
>> >
>> > Simon
>>
>> I answered that earlier: If you let the MFC message pump operate
>> normally then your OnReceive override will be called when a reply comes
>> in from the server. It is a message handler: If you get a mouse click a
>> message comes in; If you get data from the server OnReceive is called.
>>
>> --
>> 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: unable to receive mail from certain domains
    ... We did try the telnet from their end and there was no delay. ... Bharat Suneja wrote: ... delay is from the time the message is sent out until my Exchange server ... MVP - Exchange ...
    (microsoft.public.exchange.admin)
  • Re: Messages showing up in Outlook with a delay
    ... Susan Conkey [MVP] ... with a delay in Outlook. ... yesterday and the queues are empty. ... server using MAPI, ...
    (microsoft.public.exchange.admin)
  • Re: Outlook wont send large attachments
    ... the one operating your own personal mail server. ... header to the e-mail client while they interrogate the message but that only ... the timeout due to excessive delay. ...
    (microsoft.public.outlook)
  • Re: WTSOpenServer() - WtsAPI32
    ... No, no delay locally. ... I'm running a Win XP Pro workstation, and my WTS ... Now I just need to figure out how to associate the server name (which I have ... in an ArrayList) with the WTS server handle that the WTSOpenServer() ...
    (microsoft.public.windows.terminal_services)
  • Re: Troubleshooting that lousy "Requesting Data..." dialog box in OLXP
    ... This even happens when we're on the same network segment. ... Does increasing the timeout simply delay the box popping up or does it have ... Is there any reason why Outlook 98 did not have this issue? ... What about the server ...
    (microsoft.public.exchange.connectivity)