From 030eb6d022c00bc978d8d9f68de2780ad719bc5e Mon Sep 17 00:00:00 2001 From: xecarlox94 Date: Sun, 10 Nov 2024 19:23:23 +0000 Subject: [PATCH] tested example --- haskell/lib/Engine.hs | 20 +++++++++++++++++--- haskell/src/Main.hs | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/haskell/lib/Engine.hs b/haskell/lib/Engine.hs index ee0d232..51562a1 100644 --- a/haskell/lib/Engine.hs +++ b/haskell/lib/Engine.hs @@ -6,10 +6,14 @@ module Engine where +import Control.Concurrent +import Data.Char (toLower) +import System.IO +import Control.Monad (when) + import System.Process ( terminateProcess ) -import Control.Concurrent ( threadDelay ) import API ( P2PRCapi(..) @@ -105,7 +109,6 @@ runP2PRC portNumber domainName = do mapPortOut <- execMapPort $ MkMapPortRequest portNumber domainName - case mapPortOut of (Right v) -> print v (Left e) -> print e @@ -123,11 +126,22 @@ runP2PRC portNumber domainName = do -- - Use remote machine p2prc cmd to map a port using --mp -- - Return back the exposed public IP and port number back to stdout + exitOnQ $ terminateProcess startProcessHandle - terminateProcess startProcessHandle (Left err) -> print err (Left err) -> print err + where + + + exitOnQ :: IO () -> IO () + exitOnQ f = do + hSetBuffering stdin NoBuffering + c <- getChar + when (toLower c /= 'q') $ exitOnQ f + f + + diff --git a/haskell/src/Main.hs b/haskell/src/Main.hs index fe3d37c..cfe4a4c 100644 --- a/haskell/src/Main.hs +++ b/haskell/src/Main.hs @@ -8,4 +8,4 @@ import P2PRC main :: IO () main = - runP2PRC 3333 "jose.akilan.io" + runP2PRC 8080 "jose.akilan.io"