Re: how to avoid recv() blocking issue?

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



Ah, I think I didn't read your post carefully... Yes, for a
blocking socket it's certainly possible. If you don't send
any data and the peer neglects to close the connection
(for example as the result of a machine crash), the TCP
stack would simply get no indiciation that the connection
is gone. Yet another reason to not use blocking sockets...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Chris Becke" <chris.becke@xxxxxxxxx> wrote in message
news:uY0zYVwAHHA.2140@xxxxxxxxxxxxxxxxxxxxxxx
when the non blocking socket is setup in blocking mode... I did specify
blocking socket.

With a non blocking socket, yeah, i dont know if any situation that would
make it block.


"Alexander Nickolov" <agnickolov@xxxxxxxx> wrote in message
news:u7VgazrAHHA.1780@xxxxxxxxxxxxxxxxxxxxxxx
Can you post the circumstances? I've never heard before
of a socket in non-blocking mode blocking in recv, at
least on a machine without third-party LSPs (all bets are
off if one has a third party LSP...).

Besides, it's not recommended even by Microsoft to ever
check the socket explicitly for data availablity! That
constitutes poor performance.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Chris Becke" <chris.becke@xxxxxxxxx> wrote in message
news:O1wISQkAHHA.4292@xxxxxxxxxxxxxxxxxxxxxxx
It is possible to be stuck in a blocking call to recv, and for the
server
to
drop the connection abnormally such that the blocking recv will never
exit.
I really dont see how that is happening in this situation.

However, because of that possibility, all my calls to blocking recv use
the
basic code:

first, use ioctlsocket(s,FIONREAD,&cbRead); to check if there is data
available.
If there is, go straight to recv, otherwise call
select(0,fd_s,0,0,&tv_timeout); with a timeout.

"Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx> wrote in message
news:esLEwWjAHHA.2140@xxxxxxxxxxxxxxxxxxxxxxx
That strange because WSAEventSelect() as WSAAsyncSelect do set socket
as
non-blocked. Check that you if you used them or through
ioctlsocket() with FIONBIO set to 1 on recv() you have to return with
WSAWOULDBLOCK warning or data
Arkady

"Alexander Cherny" <black@xxxxxxxxxxxxxxx> wrote in message
news:%23Wyf0XfAHHA.4292@xxxxxxxxxxxxxxxxxxxxxxx
hi all,

i got a problem with recv().

there's a thread to receive data from a server. periodically this
thread
has to stop (to let others to do some work). i created some events
to
check them inside the thread. the problem happens, when recv()
starts
and
does not receive any data from a server. this time the thread is
stuck -
recv() just waits for data, and i can't stop the thread well (not
using
TerminateThread() - btw, it's not a good idea, because a socket
remains
"anchored" by the thread).

is there any way to "unblock" recv() somehow? WSAEventSelect() does
not
help. looks like it's for different purposes.

thanks a lot.

--
alex c.











.



Relevant Pages

  • Re: how to avoid recv() blocking issue?
    ... when the non blocking socket is setup in blocking mode... ... drop the connection abnormally such that the blocking recv will never ... I really dont see how that is happening in this situation. ...
    (microsoft.public.win32.programmer.networks)
  • Re: HELP: ioctlsocket sometimes shows 0 bytes available when there
    ... Microsoft MVP, MCSD ... >> There is nothing wrong with a non-blocking socket. ... > that remaining data will arrive at all, so recv() still will block. ... > a) running blocking recv() in a separate thread ...
    (microsoft.public.win32.programmer.networks)
  • Re: select.select and socket.setblocking
    ... recv (again, assuming that you use TCP as protocol, that is AF_INET, ... which in the blocking case would wait to receive all the ... with TCP protocol recv only returned less than ... use socket in blocking mode ...
    (comp.lang.python)
  • Re: recv blocks although socket is ready
    ... The problem is, that in blocking mode ... select sometimes reports the socket readable and then the following ... following call to recv() blocks. ...
    (microsoft.public.win32.programmer.networks)
  • Re: select.select and socket.setblocking
    ... select between blocking and non-blocking mode. ... recv, which in the blocking case would wait to receive all the bytes that you requested, ... with TCP protocol recv only returned less than the required bytes if the remote end disconnects. ... If my process has only to deal with socket I/O, I make a blocking select, and then make an 'exact' recv on whichever socket the select signals. ...
    (comp.lang.python)