@@ -9,6 +9,8 @@ defmodule SSHKit.Channel do
99 * `id` - the unique channel id
1010 """
1111
12+ alias SSHKit.Connection
13+
1214 defstruct [ :connection , :type , :id ]
1315
1416 @ type t ( ) :: % __MODULE__ { }
@@ -30,6 +32,7 @@ defmodule SSHKit.Channel do
3032 * `:initial_window_size` - defaults to 128 KiB
3133 * `:max_packet_size` - defaults to 32 KiB
3234 """
35+ @ spec open ( Connection . t ( ) , keyword ( ) ) :: { :ok , t ( ) } | { :error , term ( ) }
3336 def open ( conn , options \\ [ ] ) do
3437 timeout = Keyword . get ( options , :timeout , :infinity )
3538 ini_window_size = Keyword . get ( options , :initial_window_size , 128 * 1024 )
@@ -51,8 +54,7 @@ defmodule SSHKit.Channel do
5154
5255 For more details, see [`:ssh_connection.subsystem/4`](http://erlang.org/doc/man/ssh_connection.html#subsystem-4).
5356 """
54- @ spec subsystem ( channel :: struct ( ) , subsystem :: String . t ( ) , options :: list ( ) ) ::
55- :success | :failure | { :error , reason :: String . t ( ) }
57+ @ spec subsystem ( t ( ) , binary ( ) , keyword ( ) ) :: :success | :failure | { :error , term ( ) }
5658 def subsystem ( channel , subsystem , options \\ [ ] ) do
5759 timeout = Keyword . get ( options , :timeout , :infinity )
5860 @ core . subsystem ( channel . connection . ref , channel . id , to_charlist ( subsystem ) , timeout )
@@ -65,6 +67,7 @@ defmodule SSHKit.Channel do
6567
6668 For more details, see [`:ssh_connection.close/2`](http://erlang.org/doc/man/ssh_connection.html#close-2).
6769 """
70+ @ spec close ( t ( ) ) :: :ok
6871 def close ( channel ) do
6972 @ core . close ( channel . connection . ref , channel . id )
7073 end
@@ -81,6 +84,7 @@ defmodule SSHKit.Channel do
8184 `loop/4` may be used to process any channel messages received as a result of
8285 executing `command` on the remote.
8386 """
87+ @ spec exec ( t ( ) , binary ( ) | charlist ( ) , timeout ( ) ) :: :success | :failure | { :error , term ( ) }
8488 def exec ( channel , command , timeout \\ :infinity )
8589
8690 def exec ( channel , command , timeout ) when is_binary ( command ) do
@@ -94,10 +98,11 @@ defmodule SSHKit.Channel do
9498 @ doc """
9599 Allocates PTTY.
96100
97- Returns `:success`.
101+ Returns `:success`, `:failure` or `{:error, reason}` .
98102
99103 For more details, see [`:ssh_connection.ptty_alloc/4`](http://erlang.org/doc/man/ssh_connection.html#ptty_alloc-4).
100104 """
105+ @ spec ptty ( t ( ) , keyword ( ) , timeout ( ) ) :: :success | :failure | { :error , term ( ) }
101106 def ptty ( channel , options \\ [ ] , timeout \\ :infinity ) do
102107 @ core . ptty_alloc ( channel . connection . ref , channel . id , options , timeout )
103108 end
@@ -111,6 +116,8 @@ defmodule SSHKit.Channel do
111116
112117 For more details, see [`:ssh_connection.send/5`](http://erlang.org/doc/man/ssh_connection.html#send-5).
113118 """
119+ @ spec send ( t ( ) , non_neg_integer ( ) , term ( ) , timeout ( ) ) ::
120+ :ok | { :error , :timeout } | { :error , :closed }
114121 def send ( channel , type \\ 0 , data , timeout \\ :infinity )
115122
116123 def send ( channel , type , data , timeout ) when is_binary ( data ) or is_list ( data ) do
@@ -131,6 +138,7 @@ defmodule SSHKit.Channel do
131138
132139 For more details, see [`:ssh_connection.send_eof/2`](http://erlang.org/doc/man/ssh_connection.html#send_eof-2).
133140 """
141+ @ spec eof ( t ( ) ) :: :ok | { :error , term ( ) }
134142 def eof ( channel ) do
135143 @ core . send_eof ( channel . connection . ref , channel . id )
136144 end
@@ -155,6 +163,7 @@ defmodule SSHKit.Channel do
155163
156164 For more details, see [`:ssh_connection`](http://erlang.org/doc/man/ssh_connection.html).
157165 """
166+ @ spec recv ( t ( ) , timeout ( ) ) :: { :ok , tuple ( ) } | { :error , term ( ) }
158167 def recv ( channel , timeout \\ :infinity ) do
159168 ref = channel . connection . ref
160169 id = channel . id
@@ -173,6 +182,7 @@ defmodule SSHKit.Channel do
173182
174183 Returns `:ok`.
175184 """
185+ @ spec flush ( t ( ) , timeout ( ) ) :: :ok
176186 def flush ( channel , timeout \\ 0 ) do
177187 ref = channel . connection . ref
178188 id = channel . id
@@ -191,6 +201,7 @@ defmodule SSHKit.Channel do
191201
192202 For more details, see [`:ssh_connection.adjust_window/3`](http://erlang.org/doc/man/ssh_connection.html#adjust_window-3).
193203 """
204+ @ spec adjust ( t ( ) , non_neg_integer ( ) ) :: :ok
194205 def adjust ( channel , size ) when is_integer ( size ) do
195206 @ core . adjust_window ( channel . connection . ref , channel . id , size )
196207 end
0 commit comments