@@ -9,6 +9,8 @@ defmodule SSHKit.Channel do
9
9
* `id` - the unique channel id
10
10
"""
11
11
12
+ alias SSHKit.Connection
13
+
12
14
defstruct [ :connection , :type , :id ]
13
15
14
16
@ type t ( ) :: % __MODULE__ { }
@@ -30,6 +32,7 @@ defmodule SSHKit.Channel do
30
32
* `:initial_window_size` - defaults to 128 KiB
31
33
* `:max_packet_size` - defaults to 32 KiB
32
34
"""
35
+ @ spec open ( Connection . t ( ) , keyword ( ) ) :: { :ok , t ( ) } | { :error , term ( ) }
33
36
def open ( conn , options \\ [ ] ) do
34
37
timeout = Keyword . get ( options , :timeout , :infinity )
35
38
ini_window_size = Keyword . get ( options , :initial_window_size , 128 * 1024 )
@@ -51,8 +54,7 @@ defmodule SSHKit.Channel do
51
54
52
55
For more details, see [`:ssh_connection.subsystem/4`](http://erlang.org/doc/man/ssh_connection.html#subsystem-4).
53
56
"""
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 ( ) }
56
58
def subsystem ( channel , subsystem , options \\ [ ] ) do
57
59
timeout = Keyword . get ( options , :timeout , :infinity )
58
60
@ core . subsystem ( channel . connection . ref , channel . id , to_charlist ( subsystem ) , timeout )
@@ -65,6 +67,7 @@ defmodule SSHKit.Channel do
65
67
66
68
For more details, see [`:ssh_connection.close/2`](http://erlang.org/doc/man/ssh_connection.html#close-2).
67
69
"""
70
+ @ spec close ( t ( ) ) :: :ok
68
71
def close ( channel ) do
69
72
@ core . close ( channel . connection . ref , channel . id )
70
73
end
@@ -81,6 +84,7 @@ defmodule SSHKit.Channel do
81
84
`loop/4` may be used to process any channel messages received as a result of
82
85
executing `command` on the remote.
83
86
"""
87
+ @ spec exec ( t ( ) , binary ( ) | charlist ( ) , timeout ( ) ) :: :success | :failure | { :error , term ( ) }
84
88
def exec ( channel , command , timeout \\ :infinity )
85
89
86
90
def exec ( channel , command , timeout ) when is_binary ( command ) do
@@ -94,10 +98,11 @@ defmodule SSHKit.Channel do
94
98
@ doc """
95
99
Allocates PTTY.
96
100
97
- Returns `:success`.
101
+ Returns `:success`, `:failure` or `{:error, reason}` .
98
102
99
103
For more details, see [`:ssh_connection.ptty_alloc/4`](http://erlang.org/doc/man/ssh_connection.html#ptty_alloc-4).
100
104
"""
105
+ @ spec ptty ( t ( ) , keyword ( ) , timeout ( ) ) :: :success | :failure | { :error , term ( ) }
101
106
def ptty ( channel , options \\ [ ] , timeout \\ :infinity ) do
102
107
@ core . ptty_alloc ( channel . connection . ref , channel . id , options , timeout )
103
108
end
@@ -111,6 +116,7 @@ defmodule SSHKit.Channel do
111
116
112
117
For more details, see [`:ssh_connection.send/5`](http://erlang.org/doc/man/ssh_connection.html#send-5).
113
118
"""
119
+ @ spec send ( t ( ) , non_neg_integer ( ) , term ( ) , timeout ( ) ) :: :ok | { :error , :timeout } | { :error , :closed }
114
120
def send ( channel , type \\ 0 , data , timeout \\ :infinity )
115
121
116
122
def send ( channel , type , data , timeout ) when is_binary ( data ) or is_list ( data ) do
@@ -131,6 +137,7 @@ defmodule SSHKit.Channel do
131
137
132
138
For more details, see [`:ssh_connection.send_eof/2`](http://erlang.org/doc/man/ssh_connection.html#send_eof-2).
133
139
"""
140
+ @ spec eof ( t ( ) ) :: :ok | { :error , term ( ) }
134
141
def eof ( channel ) do
135
142
@ core . send_eof ( channel . connection . ref , channel . id )
136
143
end
@@ -155,6 +162,7 @@ defmodule SSHKit.Channel do
155
162
156
163
For more details, see [`:ssh_connection`](http://erlang.org/doc/man/ssh_connection.html).
157
164
"""
165
+ @ spec recv ( t ( ) , timeout ( ) ) :: { :ok , tuple ( ) } | { :error , term ( ) }
158
166
def recv ( channel , timeout \\ :infinity ) do
159
167
ref = channel . connection . ref
160
168
id = channel . id
@@ -173,6 +181,7 @@ defmodule SSHKit.Channel do
173
181
174
182
Returns `:ok`.
175
183
"""
184
+ @ spec flush ( t ( ) , timeout ( ) ) :: :ok
176
185
def flush ( channel , timeout \\ 0 ) do
177
186
ref = channel . connection . ref
178
187
id = channel . id
@@ -191,6 +200,7 @@ defmodule SSHKit.Channel do
191
200
192
201
For more details, see [`:ssh_connection.adjust_window/3`](http://erlang.org/doc/man/ssh_connection.html#adjust_window-3).
193
202
"""
203
+ @ spec adjust ( t ( ) , non_neg_integer ( ) ) :: :ok
194
204
def adjust ( channel , size ) when is_integer ( size ) do
195
205
@ core . adjust_window ( channel . connection . ref , channel . id , size )
196
206
end
0 commit comments