#!/bin/bash proc _hash { echo $Pid.$[date +'%s.%N].$RANDOM } proc balls::server { balls::load_app global http_sock := "$BALLS_TMP/balls.http.$Pid.sock" test -p $http_sock || mkfifo $http_sock while true { cat $http_sock | nc -l -p $BALLS_PORT | shell { http::parse_request balls::route > $http_sock } } } proc cleanup { rm -f $headers_sock $http_sock } trap 'cleanup; exit' INT proc balls::load_app { source $BALLS_ACTIONS/*.sh } (CommandList children: [ (FuncDef name: _hash body: (BraceGroup children: [ (C {(echo)} {($ VSub_Dollar "$$") (.) (CommandSubPart command_list: (CommandList children: [(C {(date)} {(Lit_Other "+") (SQ <"%s.%N">)})] ) left_token: spids: [15 22] ) (.) ($ VSub_Name "$RANDOM") } ) ] spids: [8] ) spids: [4 7] ) (FuncDef name: "balls::server" body: (BraceGroup children: [ (C {(balls) (Lit_Other ":") (Lit_Other ":") (load_app)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:http_sock) op: Equal rhs: {($ VSub_Name "$BALLS_TMP") (/balls.http.) ($ VSub_Dollar "$$") (.sock)} spids: [45] ) ] spids: [45] ) (AndOr children: [ (C {(Lit_Other "[")} {(-p)} {($ VSub_Name "$http_sock")} {(Lit_Other "]")}) (C {(mkfifo)} {($ VSub_Name "$http_sock")}) ] op_id: Op_DPipe ) (While cond: [(Sentence child:(C {(true)}) terminator:)] body: (DoGroup children: [ (Pipeline children: [ (C {(cat)} {($ VSub_Name "$http_sock")}) (C {(nc)} {(-l)} {(-p)} {($ VSub_Name "$BALLS_PORT")}) (Subshell child: (CommandList children: [ (C {(http) (Lit_Other ":") (Lit_Other ":") (parse_request)}) (SimpleCommand words: [{(balls) (Lit_Other ":") (Lit_Other ":") (route)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {($ VSub_Name "$http_sock")} spids: [106] ) ] ) ] ) spids: [92 111] ) ] negated: False ) ] spids: [73 114] ) ) ] spids: [36] ) spids: [29 35] ) (FuncDef name: cleanup body: (BraceGroup children: [ (C {(rm)} {(-f)} {(DQ ($ VSub_Name "$headers_sock"))} {(DQ ($ VSub_Name "$http_sock"))}) ] spids: [123] ) spids: [119 122] ) (C {(trap)} {(SQ <"cleanup; exit">)} {(INT)}) (FuncDef name: "balls::load_app" body: (BraceGroup children: [(C {(.)} {($ VSub_Name "$BALLS_ACTIONS") (/) (Lit_Other "*") (.sh)})] spids: [157] ) spids: [150 156] ) ] )