-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #18: change - add json/utf8 packages, receive code_id and code, …
…fake execute code routine
- Loading branch information
Showing
2 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
import qualified Data.ByteString.Char8 as C | ||
import qualified Data.ByteString.UTF8 as U | ||
import qualified Data.Map as Map | ||
import Debug.Trace | ||
|
||
import Data.Aeson | ||
import System.ZMQ4.Monadic | ||
|
||
main :: IO () | ||
|
||
main = do | ||
let port = "tcp://*:2001" | ||
putStrLn "Started..." | ||
let | ||
putStrLn "serving at port 2001..." | ||
runZMQ $ do | ||
skt <- socket Rep | ||
bind skt port | ||
loop skt | ||
putStrLn "exit." | ||
|
||
where | ||
loop skt = do | ||
msg <- receive skt | ||
send skt [] msg | ||
loop skt | ||
port = "tcp://*:2001" | ||
loop skt = do | ||
code_id <- receive skt | ||
code <- receive skt | ||
|
||
-- TODO: execute code routine | ||
let (out, err, exceptions) = executeCode (show code_id) (U.toString code) | ||
|
||
let result = Map.fromList [("stdout", out), ("stderr", err), ("exceptions", exceptions)] | ||
send skt [] code_id | ||
loop skt | ||
|
||
executeCode :: String -> String -> (String, String, String) | ||
executeCode code_id code = ("fake out", "fake err", "fake exceptions") |