Problem with Winsock C++ Service on NT4

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
I have a service running on WinNT 4 that serves the wireless connection for hand-held devices in retail stores. Recently, I changed the service to handle all communications for the client itself rather than spawining child processes to do the work. When a client connects on the socket, I use DuplicateHandle( ) to create a new handle to the same socket and pass it to a child thread that does the database work and returns the reply to the client. When CreateThread( ) succeeds, the parent (service) thread closes the handle that it has. Intermittenly (less that 5% of the time) the server send( ) returns errror 10038 (socket operation on non-socket). The handle to the socket is lost and the client which is blocking on the recv( ) appears to be hung.

Any suggestions?

Thanks in advance.
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
Code:
#include "a_really_naughty_word.h"
using namespace std;

void main( void )
{
   A_REALLY_NAUGHTY_WORD *pFilth = new A_REALLY_NAUGHTY_WORD;
   pFilth->Execute();
}
 
Joined
Nov 24, 2002
Messages
2,438
Sorry Coderitr, I'm not ignoring you but I'm not really the guy to ask about sockets :(. I can follow what you are doing and how it should function but I don't have the depth to make any sensible suggestions as to what is going wrong.

I have asked my "overlord in these matters" and am waiting for him to come back to me on it.
 
Joined
Nov 24, 2002
Messages
2,438
Quick few lines at speed passed by my friend.

The handles that get dropped, have you got them set up correctly at inception regarding inheritance by the thread they get passed to? I'm not sure of the exact implications of what he asked myself so I hope that makes it at least partially clear.
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
Albert I did not think that I was being ignored. It seems my questions are harder to answer than most. :D I may have resolved this issue by eliminating the CreateThread( ) portion of the code and handling the client communication synchronously. I've installed the revisions in beta and time will tell as the users beat it up.

Thanks.
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
If the inheritance wasn't getting passed correctly I would expect a lot more failures than I'm getting. Anyway, see above. :)
 
Joined
Nov 24, 2002
Messages
2,438
Back again,

Some thoughts relayed on to you Coderitr.

Your three ways of approaching the problem, spawning separate processes, separate threads, and synchronously are all sound of course, but Graeme felt you wouldn't be happy with your current synchronous solution for long as the others are "nicer" solutions. :D Given the information we have at the moment he suggested that the problem was most likely to lie with the DuplicateHandle() function possibly failing and asked if you have tried to check this. It returns a BOOL FALSE value on fail so is easy to utilise of course. If you find it is failing he also suggested using GetLastError() to try to identify what is the cause of the fail should that be it.

Also is the softweare currently written to post to log files?

Any help?
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
What kind of developer do you think I am? :D Of course I checked the return value from DuplicateHandle( ). :D ( Please take that in the jocular spirit in which it is intended.) I've never seen DuplicateHandle( ) fail in this instance and the recv( ) works fine. My beta test of the synchronous solution has been code-related problem free so far. I'll expand the test pool next week. I was skeptical of this approach at first because if say 8 devices hit the service all at the same time then the last one has to wait the length to time that it takes to process a single client * 7 but I installed a process timer to gauge the time it takes to get a message, retrieve data from the database and return the reply to the client. The average is around 70 ms so I'm pretty happy about that.

Thanks to you and your colleague for your input.
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
BTW, yes the software writes to a log file. Actually its a log table in my database. That's how I found the problem to begin with.
 
Joined
Nov 24, 2002
Messages
2,438
Hmmm! He did think it was extremely unlikely you would have missed that point but I suggested posting it anyway as we have all been at the point where you just can't see the wood for the trees and you just need something to jog the brain. :) The idea of DuplicateHandle() failing was really considered to be perhaps an unusual resource issue not knowing the setup in which you were installing the software, hence the suggestion to use GetLastError() at that point to get a better view of the nature of what caused the problem. Just out of interest, how many devices does this setup accomodate?

If anything other thoughts come up I will pass them on. (Despite his unwillingness to accept a synchronous solution as final on purist grounds :D, 70ms doesn't seem a heavy penalty to me ;).)

Good luck.
 

coderitr

Thread Starter
Joined
Oct 12, 2003
Messages
3,015
Since we're running the service on a PII-350 we hope to be able to support up to 6 wireless devices at a time on this service. My company is expanding, however and this application will be installed later this year in a sister company's stores with P4 processors in the server. In that case, the number of devices is almost without limit. The only obstacle to an increased number of devices on this service is the performance degradation that can effect all of them as you add more clients.

Just FYI, my job is to develop retail back office applications (employee time and attendance, inventory tracking, shipping and receiving, etc) for a chain of about 350 stores. This wireless application is part of that. The DOS clients run applications locally and communicate with the server database via this socket connection managed by the service.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top