1

I'm in the process of designing an application that will run on a headless Windows CE 6.0 device. The idea is to make an application that will be started at startup and run until powered off. (Basically it will look like a service, but an application is easier to debug without the complete hassle to stop/deploy/start/attach to process procedure)

My concern is what will happen during development. If I debug/deploy the application I see no way of closing it in a friendly and easy way. (Feel free to suggest if this can be done in a better/user friendly way) I will just stop the debugger and the result will be WSACleanup is not called.

Now, the question. What is the consequence of not calling WSACleanup? Will I be able to start and run the winsock application again using the debugger? Or will there be a resource leak preventing me to do so?

Thanks in advance, Jef

MD XF
  • 7,860
  • 7
  • 40
  • 71
Jef Patat
  • 999
  • 1
  • 10
  • 26
  • 1
    I'm not intimately familiar with Winsock in particular, but it is a general rule of Windows APIs that resources are not leaked when a process exits without cleaning up after itself. It is possible that there will be some differences in behaviour, e.g., connections might remain open until timed out, listening sockets might not become available again quite as quickly as they otherwise would, and that sort of thing. Nothing too serious, but there might be a few annoyances. At any rate, it will be safe for you to experiment and see whether it works for you or not. – Harry Johnston Oct 22 '14 at 21:22
  • I thought of experimenting with it as well, but that doesn't necessarily lead to understanding the system at full. I think you are quite right regarding the resources. I was not aware that the OS cleans up the mess you leave behind. I knew about allocated memory, but not about the other resources. With you answer in mind I did some further looking up and searched specifically for 'sockets'. I found [this](http://superuser.com/questions/375604/does-windows-take-care-of-closing-sockets-when-processes-exit) which basically confirms your answer. How can I mark your comment as answer? – Jef Patat Oct 23 '14 at 09:07

1 Answers1

0

I think that Harry Johnston comment is correct. Even if your application has no UI you can find a way to close it gracefully. I suppose that you have one or more threads in loops, you can add a named manual reset event that is checked (or can be used for waits instead of Sleep()) inside the loop condition and build a small application that opens the event using the same name, sets it and quits. This would force also your service app to close. It may not be needed for debugging, but it may be useful also if you'll need to update your software and this requires that your main service is not running.

Valter Minute
  • 2,177
  • 1
  • 11
  • 13
  • Thanks for mentioning the update process. I didn't think of that yet. Your idea sounds like a good starting point. – Jef Patat Oct 23 '14 at 09:02