From 55827b827e3ef056fcba9ddd13115ee7d65b82d3 Mon Sep 17 00:00:00 2001 From: pmeinhardt Date: Tue, 15 Dec 2020 00:35:21 +0100 Subject: [PATCH] Drop Channel.loop/4, obsoleted by SSHKit.stream/1 --- lib/sshkit/ssh/channel.ex | 102 -------------------------------------- 1 file changed, 102 deletions(-) diff --git a/lib/sshkit/ssh/channel.ex b/lib/sshkit/ssh/channel.ex index f49d08fc..098fe860 100644 --- a/lib/sshkit/ssh/channel.ex +++ b/lib/sshkit/ssh/channel.ex @@ -195,106 +195,4 @@ defmodule SSHKit.SSH.Channel do def adjust(channel, size) when is_integer(size) do channel.impl.adjust_window(channel.connection.ref, channel.id, size) end - - @doc """ - Loops over channel messages until the channel is closed, or looping is stopped - explicitly. - - Expects an accumulator on each call that determines how to proceed: - - 1. `{:cont, acc}` - - The loop will wait for an inbound message. It will then pass the message and - current `acc` to the looping function. `fun`'s return value is the - accumulator for the next cycle. - - 2. `{:cont, message, acc}` - - Sends a message to the remote end of the channel before waiting for a - message as outlined in the `{:cont, acc}` case above. `message` may be one - of the following: - - * `{0, data}` or `{1, data}` - sends normal or stderr data to the remote - * `data` - is a shortcut for `{0, data}` - * `:eof` - sends EOF - - 3. `{:halt, acc}` - - Terminates the loop, returning `{:halted, acc}`. - - 4. `{:suspend, acc}` - - Suspends the loop, returning `{:suspended, acc, continuation}`. - `continuation` is a function that accepts a new accumulator value and that, - when called, will resume the loop. - - `timeout` specifies the maximum wait time for receiving and sending individual - messages. - - Once the final `{:closed, channel}` message is received, the loop will - terminate and return `{:done, acc}`. The channel will be closed if it has - not been closed before. - """ - def loop(channel, timeout \\ :infinity, acc, fun) - - def loop(channel, timeout, {:cont, msg, acc}, fun) do - case lsend(channel, msg, timeout) do - :ok -> loop(channel, timeout, {:cont, acc}, fun) - err -> halt(channel, err) - end - end - - def loop(channel, timeout, {:cont, acc}, fun) do - case recv(channel, timeout) do - {:ok, msg} -> - if elem(msg, 0) == :closed do - {_, acc} = fun.(msg, acc) - done(channel, acc) - else - :ok = ljust(channel, msg) - loop(channel, timeout, fun.(msg, acc), fun) - end - err -> halt(channel, err) - end - end - - def loop(channel, _, {:halt, acc}, _) do - halt(channel, acc) - end - - def loop(channel, timeout, {:suspend, acc}, fun) do - suspend(channel, acc, fun, timeout) - end - - defp halt(channel, acc) do - :ok = close(channel) - :ok = flush(channel) - {:halted, acc} - end - - defp suspend(channel, acc, fun, timeout) do - {:suspended, acc, &loop(channel, timeout, &1, fun)} - end - - defp done(_, acc) do - {:done, acc} - end - - defp lsend(_, nil, _), do: :ok - - defp lsend(channel, :eof, _), do: eof(channel) - - defp lsend(channel, {type, data}, timeout) do - send(channel, type, data, timeout) - end - - defp lsend(channel, data, timeout) do - send(channel, 0, data, timeout) - end - - defp ljust(channel, {:data, _, _, data}) do - adjust(channel, byte_size(data)) - end - - defp ljust(_, _), do: :ok end