Skip to content

Commit 55827b8

Browse files
committed
Drop Channel.loop/4, obsoleted by SSHKit.stream/1
1 parent 540b3dc commit 55827b8

File tree

1 file changed

+0
-102
lines changed

1 file changed

+0
-102
lines changed

lib/sshkit/ssh/channel.ex

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -195,106 +195,4 @@ defmodule SSHKit.SSH.Channel do
195195
def adjust(channel, size) when is_integer(size) do
196196
channel.impl.adjust_window(channel.connection.ref, channel.id, size)
197197
end
198-
199-
@doc """
200-
Loops over channel messages until the channel is closed, or looping is stopped
201-
explicitly.
202-
203-
Expects an accumulator on each call that determines how to proceed:
204-
205-
1. `{:cont, acc}`
206-
207-
The loop will wait for an inbound message. It will then pass the message and
208-
current `acc` to the looping function. `fun`'s return value is the
209-
accumulator for the next cycle.
210-
211-
2. `{:cont, message, acc}`
212-
213-
Sends a message to the remote end of the channel before waiting for a
214-
message as outlined in the `{:cont, acc}` case above. `message` may be one
215-
of the following:
216-
217-
* `{0, data}` or `{1, data}` - sends normal or stderr data to the remote
218-
* `data` - is a shortcut for `{0, data}`
219-
* `:eof` - sends EOF
220-
221-
3. `{:halt, acc}`
222-
223-
Terminates the loop, returning `{:halted, acc}`.
224-
225-
4. `{:suspend, acc}`
226-
227-
Suspends the loop, returning `{:suspended, acc, continuation}`.
228-
`continuation` is a function that accepts a new accumulator value and that,
229-
when called, will resume the loop.
230-
231-
`timeout` specifies the maximum wait time for receiving and sending individual
232-
messages.
233-
234-
Once the final `{:closed, channel}` message is received, the loop will
235-
terminate and return `{:done, acc}`. The channel will be closed if it has
236-
not been closed before.
237-
"""
238-
def loop(channel, timeout \\ :infinity, acc, fun)
239-
240-
def loop(channel, timeout, {:cont, msg, acc}, fun) do
241-
case lsend(channel, msg, timeout) do
242-
:ok -> loop(channel, timeout, {:cont, acc}, fun)
243-
err -> halt(channel, err)
244-
end
245-
end
246-
247-
def loop(channel, timeout, {:cont, acc}, fun) do
248-
case recv(channel, timeout) do
249-
{:ok, msg} ->
250-
if elem(msg, 0) == :closed do
251-
{_, acc} = fun.(msg, acc)
252-
done(channel, acc)
253-
else
254-
:ok = ljust(channel, msg)
255-
loop(channel, timeout, fun.(msg, acc), fun)
256-
end
257-
err -> halt(channel, err)
258-
end
259-
end
260-
261-
def loop(channel, _, {:halt, acc}, _) do
262-
halt(channel, acc)
263-
end
264-
265-
def loop(channel, timeout, {:suspend, acc}, fun) do
266-
suspend(channel, acc, fun, timeout)
267-
end
268-
269-
defp halt(channel, acc) do
270-
:ok = close(channel)
271-
:ok = flush(channel)
272-
{:halted, acc}
273-
end
274-
275-
defp suspend(channel, acc, fun, timeout) do
276-
{:suspended, acc, &loop(channel, timeout, &1, fun)}
277-
end
278-
279-
defp done(_, acc) do
280-
{:done, acc}
281-
end
282-
283-
defp lsend(_, nil, _), do: :ok
284-
285-
defp lsend(channel, :eof, _), do: eof(channel)
286-
287-
defp lsend(channel, {type, data}, timeout) do
288-
send(channel, type, data, timeout)
289-
end
290-
291-
defp lsend(channel, data, timeout) do
292-
send(channel, 0, data, timeout)
293-
end
294-
295-
defp ljust(channel, {:data, _, _, data}) do
296-
adjust(channel, byte_size(data))
297-
end
298-
299-
defp ljust(_, _), do: :ok
300198
end

0 commit comments

Comments
 (0)