Re: how to avoid recv() blocking issue?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


.



Relevant Pages

  • Re: Socket Exception
    ... In this case the server most likely rejected your ... connection. ... Each command is a new socket connection that is opened and closed ... /// Required designer variable. ...
    (microsoft.public.win32.programmer.networks)
  • Re: ASP.NET 2.0 - a newbie question
    ... Is there some experienced ASP.NET 2.0 developer, ... server that comes bundled Microsoft VWDE. ... A connection attempt failed because the ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.framework.aspnet)
  • error when move web service from dev machine to test server
    ... I have a simple web service that I developed on my laptop that resides ... test server, & when I try to run it, I get the error "No connection could be ... No connection could be made because the target machine actively refused it ... Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Messaging alert
    ... I was hopping that I could use sockets to create a connection back and forth in order to send the message. ... I want to be able to send a file name and other information thru the client socket to then process in the servers. ... fileevent $sock w ... At the server side I am listening at the port and execute Accept2 when the socket is created. ...
    (comp.lang.tcl)
  • Re: Strange server socket behaviour
    ... asynchronous server socket: ... I already have a perfectly working server that uses asynchronous sockets ... Why should the remote client close the connection? ... when a .NET client connects. ...
    (microsoft.public.dotnet.framework)