Re: how to avoid recv() blocking issue?



interesting. to check data availability before recv() calling. i'll try it.
thank you! :)

although, we have a weak link in a chain: a timeout. i mean, that we can't
stop the thread, until a select()'s timeout expires. is there any way to
stop waiting data in time?

btw, is it possible to make recv() to stop with a timeout by itself?

thanks anyway. it can help.

--
alex c.

"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

  • SetTimer and recv clarification needed
    ... I came across the following code to receive incoming data: ... What is the purpose of the SetTimer there? ... executed SetTimer will to force timeout inside recv. ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to avoid recv() blocking issue?
    ... using WSAEventSelect. ... we have a weak link in a chain: a timeout. ... drop the connection abnormally such that the blocking recv will never ... TerminateThread- btw, it's not a good idea, because a socket ...
    (microsoft.public.win32.programmer.networks)
  • Re: How can my application detect the physical network problem
    ... > I have set the timeout for recv and have made socket non blocking. ...
    (comp.unix.programmer)
  • Re: thread or fork.. + recv issues
    ... I was able to set a timeout and solve my problem calling this right before I ... int recvall_timeout { ... >> recv() is definately my more major problem right now... ...
    (comp.unix.programmer)
  • Re: how to avoid recv() blocking issue?
    ... now, if any data reading happens, i.e. recv() receives something, NewEvent ... alex c. ... there's a thread to receive data from a server. ... WSAEventSelect() does not ...
    (microsoft.public.win32.programmer.networks)

Loading