Re: how to avoid recv() blocking issue?

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



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?
    ... blocking socket it's certainly possible. ... Yet another reason to not use blocking sockets... ... Microsoft MVP, MCSD ... drop the connection abnormally such that the blocking recv will never ...
    (microsoft.public.win32.programmer.networks)
  • Re: Socket weirdness
    ... A plain-vanilla Winsock blocking socket will block until the entire ... requested buffer has been sent, ...
    (microsoft.public.dotnet.framework)
  • Re: When is it OK to change O_NONBLOCK mode of a socket?
    ... Connect with timeout. ... In my application, a blocking socket is more convenient, but I would ... like to set it to non-blocking mode for connectso I have control ...
    (comp.unix.programmer)
  • When is it OK to change O_NONBLOCK mode of a socket?
    ... Connect with timeout. ... In my application, a blocking socket is more convenient, but I would ... like to set it to non-blocking mode for connectso I have control ...
    (comp.unix.programmer)
  • 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)