作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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 吗?
最佳答案
虽然迟到了,但我写了一个可以提供帮助的库。它允许在 Windows 和 Linux 上进行信号处理。它可以在 hackage 上使用: https://hackage.haskell.org/package/signal
关于haskell - 如何用haskell处理Windows上的信号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10333161/
我是一名优秀的程序员,十分优秀!