Re: how to avoid recv() blocking issue?
- From: "Alexander Nickolov" <agnickolov@xxxxxxxx>
- Date: Tue, 7 Nov 2006 14:37:13 -0800
You probably want to use event-based socket model
using WSAEventSelect. In your thread you should use
WaitForMultipleObjects with the socket's event and
another event you use to signal your thread to exit.
If you use multiple sockets, you can wait on up to
64 handles within a thread, which allows a thread
to handle up to 63 sockets.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Alexander Cherny" <black@xxxxxxxxxxxxxxx> wrote in message
news:uOAJemnAHHA.4212@xxxxxxxxxxxxxxxxxxxxxxx
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 asand
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
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.
.
- Follow-Ups:
- Re: how to avoid recv() blocking issue?
- From: Alexander Cherny
- Re: how to avoid recv() blocking issue?
- From: Alexander Cherny
- Re: how to avoid recv() blocking issue?
- References:
- how to avoid recv() blocking issue?
- From: Alexander Cherny
- Re: how to avoid recv() blocking issue?
- From: Arkady Frenkel
- Re: how to avoid recv() blocking issue?
- From: Chris Becke
- Re: how to avoid recv() blocking issue?
- From: Alexander Cherny
- how to avoid recv() blocking issue?
- Prev by Date: Re: how to avoid recv() blocking issue?
- Next by Date: Re: Discover a server
- Previous by thread: Re: how to avoid recv() blocking issue?
- Next by thread: Re: how to avoid recv() blocking issue?
- Index(es):
Relevant Pages
|