Click to See Complete Forum and Search --> : NT service and sockets
myztuff
September 15th, 2003, 11:06 AM
Hi,
I am using a single connection socket in a simple NT service.
I have the problem that I can not correctly stop the service because the service is blocking on the accept() while waiting for connections.
Anyone got any suggestions?
Thanks alot,
Al.
joscollin
September 15th, 2003, 11:59 PM
Make Service a thread and socket connection as it's child thread.
myztuff
September 16th, 2003, 11:30 AM
Thanks for answering.
What I did is use the select() function with a timeout of a couple of seconds in the loop and then accept() the connection.
I have a couple of other questions though:
-Is there any disadvantage to this method?
-When stopping the service, how high can the select() timeout be, without the service giving an error?
-On an error, I set the service status to stopped, but the status in the NT service control panel is still "started".
So when I stop the service, i get told that the service has not been started.
How do you update the status in the NT service control panel?
Thanks everyone,
Al.
j0nas
September 16th, 2003, 03:02 PM
First, make sure you have followed the Knowledge Base Article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;189996
myztuff
September 16th, 2003, 05:22 PM
Thanks, although I am not using threads the article is very usefull.
I am already using the "SERVICE_STOP_PENDING" state,
but I somehow missed the wait hint.
I have one problem left, when I stop the service on an error,
the service is stopped alright but the status is not updated in the Service Control panel...
myztuff
September 17th, 2003, 07:06 AM
When starting the service, during initialization, between SERVICE-START-PENDING
and SERVICE-RUNNING, if I have an application error and set the SERVICE-STOPPED state,
I get an "internal windows NT error".
Also, after a SERVICE-RUNNING I have to sleep a couple of seconds before being able to SERVICE-STOPPED.
This produces "Access denied" entries in the System event viewer.
Anyone?
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.