有沒有像Windows上的System.Posix?如何使用haskell處理窗口上的信號?
我想下面的代碼在Windows上運行,我應該改變它?
import IO
import Control.Exception hiding (catch)
import Control.Concurrent
import Network
import System.Posix ---cannot be run on windows.
main = withSocketsDo (installHandler sigPIPE Ignore Nothing >> main')
--so the signal handler cannot be used
main' = listenOn (PortNumber 9900) >>= acceptConnections
acceptConnections sock = do
putStrLn "trying to accept" -- debug msg
[email protected](h,host,port) <- accept sock
print conn -- debug msg
forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
acceptConnections sock
talk [email protected](h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn
例如,如果我想在程序退出時,CTRL + C,我必須在C++中添加一個處理SIGINT,所以,寫一些像這樣的代碼:
void callback(int sig)
{
// printf("catch\n");
}
...
signal(SIGINT,callback);
但我不不知道如何在哈斯克爾做到這一點,使用FFI?