
The following line: foreign import shutdownHaskellAndExit :: Int -> IO () causes a compiler warning: foreign declaration uses deprecated non-standard syntax Which is the correct way to use a foreign declaration? Thanks, -- Andre

Here are the symptoms, each connection to a server sparks a thread. The thread does the processing, which may be interrupted by an asynchnonous exception (sigPIPE) at any point. Sometimes partially closed sockets are left open, even though the sparked thread has a finally clause closeing the handle for the socket. This seems to happen because a write to a socket that has been closed at the write end causes sigPIPE. If this signal is ignored an asynchronous exception is delivered to the thread, which causes a thread level exception handler to try and close the socket. The problem seems to be the finalizer itself tries to flush the write side, which results in an uncought exception meaning c_close is never called, hence the hanging socket. Here is a possible fix: handleFinalizer :: MVar Handle__ -> IO () handleFinalizer m = do h_ <- takeMVar m catch (flushWriteBufferOnly h_) (\e -> return()) -- catch exception if remote side closed let fd = fromIntegral (haFD h_) unlockFile fd when (fd /= -1) #ifdef mingw32_TARGET_OS (closeFd (haIsStream h_) fd >> return ()) #else (c_close fd >> return ()) #endif return () I think hClose should be modified also, does this sound reasonable? Regards, Keean Schupke

On Sunday 06 April 2003 04:50, Andre W B Furtado wrote:
The following line:
foreign import shutdownHaskellAndExit :: Int -> IO ()
causes a compiler warning: foreign declaration uses deprecated non-standard syntax
Which is the correct way to use a foreign declaration?
Thanks,
AFAIK ghc syntax is pretty much in line with the latest ffi spec (version 8 I think). My foreign imports tend to look something like this.. foreign import ccall unsafe "c_function_name" HaskellFunctionName :: <whatever> Regards -- Adrian Hey

Andre W B Furtado wrote:
The following line:
foreign import shutdownHaskellAndExit :: Int -> IO ()
causes a compiler warning: foreign declaration uses deprecated non-standard syntax
Which is the correct way to use a foreign declaration?
The main difference between the latest spec and the old syntax is that a calling convention specifier is now required: foreign import ccall shutdownHaskellAndExit :: Int -> IO () Cheers, Wolfgang
participants (4)
-
Adrian Hey
-
Andre W B Furtado
-
Keean
-
Wolfgang Thaller