CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2004
    Posts
    7

    Problem with Pipes in Release mode

    I am on XP and I have created an overlapped mode pipe. I call ConnectNamedPipe and set the event on wait in WaitForSingleObject. Problem comes when the WaitForSingleObject times out in release mode compile. Any other call to the pipe handle on which no client connects and connection time out throws some exception in release mode . It all works fine in debug mode.
    Code:
    OVERLAPPED op;
    op.hEvent = CreateEvent(....
    HANDLE hPipe = ConnectNamedPipe(....
    
    switch(WaitForSingleObject(op.hEvent, 5000)
    {
    case WAIT_OBJECT_0:
        ... // all works fine
        CloseHandle(hPipe); // also works fine
    
    case WAIT_TIMOUT:
        ... // any call to hPipe throws unhandled exception
        CloseHandle(hPipe); // throws unhandled exception
    }
    PS: every thing works fine in Debug mode...Exceptions come in on release mode :sigh:

    Atif

  2. #2
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Welll...what does 'ConnectNamedPipe()' return? What error code?

  3. #3
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Quote Originally Posted by atif_husain
    PS: every thing works fine in Debug mode...Exceptions come in on release mode :sigh:
    What kind of event is thrown? Have you tried debugging the release build?

  4. #4
    Join Date
    Jun 2004
    Posts
    7

    Question Re: Problem with pipes in release mode

    Thanks for your response.

    As I mentioned in my post that the handle of the pipe returned from the CreateNamePipe call is valid. I can assure you that because it all works fine when a client connects and WaitForSingleObject returns WAIT_OBJECT_0.

    But in the case the client does not connect and the WaitForSingleObject returns WAIT_TIMEOUT and I give a call to DisconnectClient and/or Close an exception in raised.

    I have tried to catch the exception in CException catch block and C 'exception' block but no luck. I catch it in catch(...) block.

    Again this only happens in release mode. I am tracing by writing log in a file.

    Thanks and please help me...

    Atif

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Quote Originally Posted by atif_husain
    Again this only happens in release mode.
    I'll ask again - have you already tried debugging the release build? And which type of exception is thrown? Also, what do you mean by "C exception block"? C has no exceptions. Is this a C++ exception, or a Win32 SEH exception? What is the exact message you are getting?

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    To ask more clearly...are you having an access violation?

  7. #7
    Join Date
    Jun 2004
    Posts
    7
    Actaully I am on XP so I get 'MyProgram has encountered a problem and need to shut down...' The technical information shows this....

    Exception Information
    Code: 0xc0000005 Flags: 0x00000000

    which I think is Access Violation due to unhandled exception.

    As for the return handle value of ConnectNamedPipe it is a number and the handle number remains same even after WaitForSingleObject times out.

    As for debugging as I mentioned I write a trace log in a txt file in every call after every statement. That is how I got to know where the problem occurs.

    The exception at present I catch in a catch(...) handler. I tried catch
    catch(CException *exp) and catch(exception *exp) but both did not work. What handler to write for a Win32 SEH exception?

    Again I appretiate all the help you are providing......

  8. #8
    Join Date
    Jun 2004
    Location
    India
    Posts
    432
    All too common, you are writing/reading to some memory you should not be. Many a times it does not shows up debug builds, but the problem is there it debug builds also. It does not shows up because of differences in the way the pointers may be initialised, un initialsed data is filled with pre determined values and such.

    Use the debugger to find the problem. Use a map file to find the problem.

    Paste the exact code as you have.
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  9. #9
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Quote Originally Posted by atif_husain
    Exception Information
    Code: 0xc0000005 Flags: 0x00000000

    which I think is Access Violation due to unhandled exception.
    Yes, that's an access violation - not due to unhandled exception, but due to an invalid pointer operation. The exception is a consequence of that, and you can't handle SEH exceptions with C++ try/catch blocks. Besides that, an access violation is a serious bug in your code which should be fixed.

    Quote Originally Posted by atif_husain
    As for debugging as I mentioned I write a trace log in a txt file in every call after every statement. That is how I got to know where the problem occurs.
    But why don't you run your code in the debugger? This will tell you in much more detail why and how the problem occurs. Besides that, it's easier and faster than writing trace logs.

  10. #10
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537

  11. #11
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

  12. #12
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured