1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Problem with Winsock C++ Service on NT4

Discussion in 'Software Development' started by coderitr, Apr 5, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. coderitr

    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.
     
  2. coderitr

    coderitr Thread Starter

    Joined:
    Oct 12, 2003
    Messages:
    3,015
    *bump*
     
  3. coderitr

    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();
    }
    
     
  4. AlbertB

    AlbertB

    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.
     
  5. AlbertB

    AlbertB

    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.
     
  6. coderitr

    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.
     
  7. coderitr

    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. :)
     
  8. AlbertB

    AlbertB

    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?
     
  9. coderitr

    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.
     
  10. coderitr

    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.
     
  11. AlbertB

    AlbertB

    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.
     
  12. coderitr

    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.
     
  13. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/217467

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice