Re: how to avoid recv() blocking issue?




"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.


Use of FIONREAD, to determine whether there is data to read as a prelude to
a call to recv(), is part of the Winsock "Lame List" and should be avoided.

If one thread is stuck inside a blocking call to recv(), then one way to get
out of it is to call closesocket() from a second thread. This will cause
recv() in the first thread to return immediately, with a return value of
zero (indicating that the connection was closed).


.



Relevant Pages

  • Re: how to avoid recv() blocking issue?
    ... 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. ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to avoid recv() blocking issue?
    ... to check data availability before recv() calling. ... we have a weak link in a chain: a timeout. ... alex c. ... However, because of that possibility, all my calls to blocking recv use ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to avoid recv() blocking issue?
    ... Microsoft MVP, MCSD ... However, because of that possibility, all my calls to blocking recv use ... recvin the first thread to return immediately, ...
    (microsoft.public.win32.programmer.networks)
  • Re: pthreads & sockets
    ... then the second thread executes a blocking recv() on the ... the first thread closes the socket (by ... I would expect the recv() to return control, ...
    (comp.os.linux.development.system)
  • Re: RAS connection and Socket status
    ... You don't need a timer to check the current RAS status. ... recv) to ensure that status messages can be processed. ... RasGetConnectStatus to check it during the connection process ...
    (microsoft.public.pocketpc.developer)