Re: CAsyncSocket blocks

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

From: Paul G. Tobey [eMVP] (ptobey_no_spam_at_instrument_no_spam.com)
Date: 05/25/04


Date: Tue, 25 May 2004 09:34:59 -0700

It's not blocking because of network I/O, but because of the OS situation.
If it were me, I'd fail the call entirely and return WSAEWOULDBLOCK in that
case, but maybe they don't do that. You can call select() in WinSock to
check for writability, but I'm not sure, if you are filling the buffers
completely, if that will work or not. By the way, there's no detectable
benefit that I've ever found to using those MFC socket things. WinSock
works virtually identically and has far fewer strange little things that
don't work. We *never* use MFC for sockets...

Paul T.

"Mikael Setterberg" <setterberg@hotmail.com> wrote in message
news:e289800e.0405250510.5490b8a2@posting.google.com...
> Thanks for your reply!
> If that is the case (which it sure looks like), why does Microsoft
> make a distiction between blocking and non-blocking sockets?
> CAsyncSocket is supposed to be non-blocking. I have not found a way of
> reading the send buffer status either so I cannot know if the call is
> going to block or not. And trying to change the TCP/IP send timeout is
> not supported by WinSock..
>
> Thanks,
>
> Mikael
>
> > I think that your guess about what it should do is wrong. When there's
no
> > more room to buffer packets, the send should *block*, waiting for enough
> > room in the buffer to store the bytes which you requested to have sent.
If
> > no space in the buffer is cleared in a sufficiently long time (the other
end
> > of the connection is no longer reachable, as far as TCP/IP can tell,
> > basically), the send will fail entirely and the socket will drop into an
> > error state where you must reconnect to reestablish communication.
> >
> > Paul T.
> >
>
>
> > > Hi,
> > > I'm developing an application where a Windows CE 4.1 client connects
> > > via Wireless Ethernet to a server on an XP machine. When the
> > > connection has been established, the client continously streams
> > > (~200KByte/s) data to the server. I use eVC and the CAsyncSocket class
> > > and is has worked out fine.
> > > However, the speed of the WL connection is not constant and depends on
> > > the distance to the nearest access point. The problem (as far as I
> > > understand) arises when the speed has dropped to a level where the
> > > TCP/IP connection cannot keep up anymore and the data in the send
> > > buffer starts to grow until the buffer is full. Suddenly the
> > > CAsyncSocket::Send function stops returning and instead gets stuck. I
> > > would expect it to return a number of bytes sent lower than originally
> > > requested in the call? I use a 200KByte send buffer at the moment.
> > > I cannot figure out why the socket behaves like this. Has anyone else
> > > experienced this?
> > >
> > > Thanks,
> > >
> > > Mikael



Relevant Pages

  • Re: Communication speed between blocking call and non blocking cal
    ... Yes i set winsock kernel buffer to 5MB. ... I got good speed and I tested for blocking and nonblocking socket and got ... Ultimately I have got good speed with non blocking socket. ...
    (microsoft.public.win32.programmer.networks)
  • Re: POSIXs send() on non blocking sockets may partially write?
    ... conforming sendimplementation on a non blocking socket is allowed ... From what I understand if the socket is ... Can I assume for a conforming POSIX implementation that "res" will be ... buffer, sendshould put one byte into the buffer and return 1. ...
    (comp.unix.programmer)
  • Re: Communication speed between blocking call and non blocking cal
    ... Ultimately I have got good speed with non blocking socket. ... Problem was I did not set winsock kernel buffer. ... As I tested blocking call is much faster than nonblocking call ...
    (microsoft.public.win32.programmer.networks)
  • Re: select(), sending and receiving data
    ... You set a socket in either the read set, the write set, or both. ... there's probably some data waiting for you to 'read' it and that calling ... there's probably some space in the write buffer and that calling 'write' ... > I thought I would set to blocking or non blocking mode with the SETs? ...
    (comp.unix.programmer)
  • Re: Communication speed between blocking call and non blocking cal
    ... You could use event based notification, ... When you use nonblocking I/O, the system may have to perform extra buffering ... data buffer until you say that you are done with it. ... I checked default socket buffer ...
    (microsoft.public.win32.programmer.networks)