Is there something like System.Posix on windows?
I want the code below to run on windows, should I change it?
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
for example ,if I want the program to quit when ctrl+c,I must add a handler for SIGINT ,so in c++,write some code like this:
void callback(int sig)
{
// printf("catch\n");
}
...
signal(SIGINT,callback);
But I don’t know how to do this in haskell,use FFI?
the code above is what i wanna do,just import the
signalfunction,with a haskell callback.