Re: how to avoid recv() blocking issue?
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Tue, 7 Nov 2006 18:00:52 -0600
"Alexander Cherny" <black@xxxxxxxxxxxxxxx> wrote in message
news:OVZFYgnAHHA.992@xxxxxxxxxxxxxxxxxxxxxxx
correct me, if i'm wrong.Yes.
WSAEventSelect() is used to fire windows events (or winsocket events),
when some network related events happen. for example,
SOCKET ListenSocket;
//... creating and binding the socket
WSAEVENT NewEvent = WSACreateEvent();
WSAEventSelect(ListenSocket, NewEvent, FD_READ);
now, if any data reading happens, i.e. recv() receives something, NewEvent
will rise. is that correct?
No. recv will complete instantly, without getting any data, with the error
but the problem is, when a server does not send any data, recv() receives
nothing, and no events rise. at this time recv() just waits, causing the
thread to be stuck.
WSAEWOULDBLOCK. Your thread will continue running. When data comes, the
socket will store it in the buffer you gave to receive and assert the event.
I always preferred to use WSAAsyncSelect, which sends a message to your
window procedure whenever data is ready. Then you call recv and it always
succeeds instantly (still best to check for WSAEWOULDBLOCK though, in case
you called recv from somewhere else). Makes it easy to process other kinds
of messages (button presses, screen painting, etc) in between packets.
please, object to me. because i don't see any solutions here.
--
alex c.
"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.
.
- 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: Alexander Cherny
- how to avoid recv() blocking issue?
- Prev by Date: Re: How to specify which network connection to be use for diff apps?
- Next by Date: Re: How to specify which network connection to be use for diff apps?
- Previous by thread: Re: how to avoid recv() blocking issue?
- Next by thread: Re: how to avoid recv() blocking issue?
- Index(es):
Loading