@@ -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,7 @@ 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 ( ) ) :: :ok | { :error , :timeout } | { :error , :closed }
114120 def send ( channel , type \\ 0 , data , timeout \\ :infinity )
115121
116122 def send ( channel , type , data , timeout ) when is_binary ( data ) or is_list ( data ) do
@@ -131,6 +137,7 @@ defmodule SSHKit.Channel do
131137
132138 For more details, see [`:ssh_connection.send_eof/2`](http://erlang.org/doc/man/ssh_connection.html#send_eof-2).
133139 """
140+ @ spec eof ( t ( ) ) :: :ok | { :error , term ( ) }
134141 def eof ( channel ) do
135142 @ core . send_eof ( channel . connection . ref , channel . id )
136143 end
@@ -155,6 +162,7 @@ defmodule SSHKit.Channel do
155162
156163 For more details, see [`:ssh_connection`](http://erlang.org/doc/man/ssh_connection.html).
157164 """
165+ @ spec recv ( t ( ) , timeout ( ) ) :: { :ok , tuple ( ) } | { :error , term ( ) }
158166 def recv ( channel , timeout \\ :infinity ) do
159167 ref = channel . connection . ref
160168 id = channel . id
@@ -173,6 +181,7 @@ defmodule SSHKit.Channel do
173181
174182 Returns `:ok`.
175183 """
184+ @ spec flush ( t ( ) , timeout ( ) ) :: :ok
176185 def flush ( channel , timeout \\ 0 ) do
177186 ref = channel . connection . ref
178187 id = channel . id
@@ -191,6 +200,7 @@ defmodule SSHKit.Channel do
191200
192201 For more details, see [`:ssh_connection.adjust_window/3`](http://erlang.org/doc/man/ssh_connection.html#adjust_window-3).
193202 """
203+ @ spec adjust ( t ( ) , non_neg_integer ( ) ) :: :ok
194204 def adjust ( channel , size ) when is_integer ( size ) do
195205 @ core . adjust_window ( channel . connection . ref , channel . id , size )
196206 end
0 commit comments