#!/usr/bin/env rune # Copyright 2004-2006 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ # Testing makeHTTPWriter. pragma.enable("easy-return") pragma.disable("explicit-result-guard") pragma.enable("accumulator") pragma.enable("unary-star") pragma.enable("dot-props") def int8 := def network := (privilegedScope) def makeListStream := def makeHTTPWriter := def makeInCharDecoder := def unpackVow(n, listVow) { return accum [] for i in 0..!n { _.with(listVow <- get(i)) } } # --- Making connection --- def [host, portStr] := interp::args def remote := network.getRemoteTCPEndpoint(host, __makeInt(portStr, 10)) when (def cr := remote.connect()) -> { def [rawIns, outs] := cr def ins := makeInCharDecoder(rawIns, "UTF-8", => stderr) def handler() { stderr.println(`%% handler: ${ins.isTerminated()} ${ins.available()}`) if (ins.isTerminated()) { interp.exitAtTop() } else { print(__makeTwine.fromChars(ins.read(0, 2**16), null)) ins <- whenAvailable(1, handler) } } ins <- whenAvailable(1, handler) outs.whenAvailable(6, fn{ stderr.println("%% writing 6 bytes") outs.write([0x30,0x31,0x32,0x33,13,10]) }) } catch p { interp.exitAtTop(p) } interp.blockAtTop()