Opened 13 years ago

Closed 13 years ago

Last modified 46 years ago

#66 closed bug (Duplicate)

Finalisation in "withSocketsDo"

Reported by: nobody Owned by: nobody
Priority: normal Milestone:
Component: hslibs/net Version: 5.02
Keywords: Cc:
Operating System: Architecture:
Type of failure: Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

I'm using GHC 5.02.2, but I believe this comment still 
applies.  While debugging my socket-using program on a 
Win98 machine my DNS (or some related part of 
networking assembly) appears to die after having my 
custom application throw an exception.  I think the 
following change will fix this:

Replace in Network.Socket module:

withSocketsDo act = do
   x <- initWinSock
   if ( x /= 0 ) then
     ioError (userError "Failed to initialise WinSock")
    else do
      v <- act
      shutdownWinSock
      return v

...with...

withSocketsDo act = do
   x <- initWinSock
   if ( x /= 0 ) then
     ioError (userError "Failed to initialise WinSock")
    else 
      act `finally` shutdownWinSock

I cannot guarantee that this is the solution to my 
problem, but when I catch all exceptions within the 
body of the argument IO action the DNS problem does 
not arise.

Also I doubt the exception utility function "finally" 
is within scope, this is simply the clearest way to 
write my fix :)

Keep up the good work!

Change History (1)

comment:1 Changed 13 years ago by simonmar

  • Status changed from assigned to closed
Note: See TracTickets for help on using tickets.