Re: how to avoid recv() blocking issue?
- From: "Alexander Cherny" <black@xxxxxxxxxxxxxxx>
- Date: Wed, 8 Nov 2006 10:08:15 -0500
the program is a windows service, that takes data from a server by a socket
all the day. there's only one connection available, so i can not use several
sockets. i've created a class, that controls all socket related operations.
the incoming data should be taken and parsed in time. i use yacc, which
creates an instance of the socket class inside and calls its appropriate
method to retrieve data. when the service stops, the "stop" event is rised,
which the socket class can catch, except the time, when recv() is in the
waiting state - it causes the mentioned blocking issue, and the service can
not stop properly.
besides, periodically (once/twice a day) a separate task should perform - to
get a different bunch of data from the same server by the same connection.
the data has different format and should be parsed by another yacc module.
ideally, the task rises a special "task" event, that can be caught by the
socket class to stop and destroy itself (with an appropriate socket closing
in a destructor). then the "task" yacc could create a new separate instance
of the socket class to perform its own actions. after finish the socket
class instance destroys itself, freeing the connection, the "task" event is
reset, and the "main" task continue to work (creating its own socket class
instance), and so on.
so it would work well, if not the blocking issue.
now i implemented Chris Becke's proposition: checking a data availability,
using ioctlsocket(), before to call recv(). it's working. but maybe there's
a better solution?
--
alex c.
"Alexander Nickolov" <agnickolov@xxxxxxxx> wrote in message
news:e4jBG1rAHHA.4740@xxxxxxxxxxxxxxxxxxxxxxx
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.
.
- 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
- Re: how to avoid recv() blocking issue?
- From: Alexander Nickolov
- how to avoid recv() blocking issue?
- Prev by Date: Re: how to avoid recv() blocking issue?
- Next by Date: Re: how to avoid recv() blocking issue?
- Previous by thread: Re: how to avoid recv() blocking issue?
- Next by thread: Re: how to avoid recv() blocking issue?
- Index(es):
Relevant Pages
|