~technomancy/shevek

445ea5b9e761944789ecb0f6a1cbab749432b2c7 — Phil Hagelberg 8 months ago fa20a5e
Accept host as argument when launching.
1 files changed, 10 insertions(+), 7 deletions(-)

M shevek.fnl
M shevek.fnl => shevek.fnl +10 -7
@@ 57,7 57,7 @@

(λ receive [conn]
  (let [(data err part) (: conn :receive "*a")]
    (when (or data (and part (~= part "")))
    (when (or data (and part (not= part "")))
      (let [(decodeds d-err) (bencode.decode_all (or data part))]
        (if decodeds
            (each [_ decoded (ipairs decodeds)]


@@ 65,16 65,19 @@
            (print (.. "Decoding error: " d-err (or data part) "\n"))))
      true)))

(local port (tonumber (. arg 1)))
(local [host port] (let [(host port) (: (. arg 1) :match "(.*):(.*)")]
                     (if host
                         [host port]
                         ["localhost" (. arg 1)])))

(when (not port)
  (: io.stderr :write "USAGE: shevek PORT\n")
  (: io.stderr :write "USAGE: shevek [HOST:]PORT\n")
  (os.exit 1))

(local conn (let [conn (assert (socket.connect "localhost" port))]
              (: conn :settimeout 0.01)
              (send {:op :clone} conn)
              conn))
(local conn (let [c (assert (socket.connect host (tonumber port)))]
              (: c :settimeout 0.01)
              (send {:op :clone} c)
              c))

(while (not session)
  (receive conn))