Windows上有类似System.Posix的东西吗?
我希望下面的代码在 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
conn@(h,host,port) <- accept sock
print conn -- debug msg
forkIO $ catch (talk conn `finally` hClose h) (\e -> print e)
acceptConnections sock
talk conn@(h,_,_) = hGetLine h >>= hPutStrLn h >> hFlush h >> talk conn
例如,如果我想让程序在 ctrl+c 时退出,我必须为 SIGINT 添加一个处理程序,所以在 c++ 中,编写如下代码:
void callback(int sig)
{
// printf("catch\n");
}
...
signal(SIGINT,callback);
但我不知道如何在haskell中做到这一点,使用FFI?