¿Hay algo así como System.Posix en Windows?cómo manejar la señal en las ventanas con haskell?
Quiero que el código siguiente se ejecute en Windows, ¿debería cambiarlo?
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
por ejemplo, si quiero el programa para dejar de fumar cuando ctrl + c, debo agregar un controlador para SIGINT, por lo que en C++, escribir algo de código como este:
void callback(int sig)
{
// printf("catch\n");
}
...
signal(SIGINT,callback);
Pero Don ¿No sabe cómo hacer esto en Haskell, use FFI?