Class: LibSSH::Channel
- Inherits:
-
Object
- Object
- LibSSH::Channel
- Defined in:
- ext/libssh_ruby/channel.c
Instance Method Summary collapse
-
#close ⇒ nil
Close a channel.
-
#eof? ⇒ Boolean
Check if remote ha sent an EOF.
-
#get_exit_status ⇒ Fixnum?
Get the exit status of the channel.
- #initialize(session) ⇒ Object constructor
-
#open_session {|channel| ... } ⇒ Object
Open a session channel, and close it after the block.
-
#poll(is_stderr: false, timeout: -1) ⇒ Fixnum?
Poll a channel for data to read.
-
#read(count, is_stderr: false, timeout: -1) ⇒ String
Read data from a channel.
-
#request_exec(cmd) ⇒ nil
Run a shell command without an interactive shell.
-
#request_pty ⇒ nil
Request a PTY.
-
#send_eof ⇒ nil
Send EOF on the channel.
-
#write(data) ⇒ Fixnum
Write data on the channel.
Constructor Details
#initialize(session) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/libssh_ruby/channel.c', line 60 static VALUE m_initialize(VALUE self, VALUE session) { ChannelHolder *holder; SessionHolder *session_holder; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); session_holder = libssh_ruby_session_holder(session); holder->channel = ssh_channel_new(session_holder->session); holder->session = session; return self; } |
Instance Method Details
#close ⇒ nil
91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/libssh_ruby/channel.c', line 91 static VALUE m_close(VALUE self) { ChannelHolder *holder; struct nogvl_channel_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_close, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); return Qnil; } |
#eof? ⇒ Boolean
261 262 263 264 265 266 |
# File 'ext/libssh_ruby/channel.c', line 261 static VALUE m_eof_p(VALUE self) { ChannelHolder *holder; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); return ssh_channel_is_eof(holder->channel) ? Qtrue : Qfalse; } |
#get_exit_status ⇒ Fixnum?
342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'ext/libssh_ruby/channel.c', line 342 static VALUE m_get_exit_status(VALUE self) { ChannelHolder *holder; struct nogvl_channel_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_get_exit_status, &args, RUBY_UBF_IO, NULL); if (args.rc == -1) { return Qnil; } else { return INT2FIX(args.rc); } } |
#open_session {|channel| ... } ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'ext/libssh_ruby/channel.c', line 118 static VALUE m_open_session(VALUE self) { ChannelHolder *holder; struct nogvl_channel_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_open_session, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); if (rb_block_given_p()) { return rb_ensure(rb_yield, Qnil, m_close, self); } else { return Qnil; } } |
#poll(is_stderr: false, timeout: -1) ⇒ Fixnum?
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'ext/libssh_ruby/channel.c', line 294 static VALUE m_poll(int argc, VALUE *argv, VALUE self) { ChannelHolder *holder; VALUE opts; const ID table[] = {id_stderr, id_timeout}; VALUE kwvals[sizeof(table) / sizeof(*table)]; struct nogvl_poll_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); rb_scan_args(argc, argv, "00:", &opts); rb_get_kwargs(opts, table, 0, 2, kwvals); if (kwvals[0] == Qundef) { args.is_stderr = 0; } else { args.is_stderr = RTEST(kwvals[0]) ? 1 : 0; } if (kwvals[1] == Qundef) { args.timeout = -1; } else { Check_Type(kwvals[1], T_FIXNUM); args.timeout = FIX2INT(kwvals[1]); } args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_poll, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); if (args.rc == SSH_EOF) { return Qnil; } else { return INT2FIX(args.rc); } } |
#read(count, is_stderr: false, timeout: -1) ⇒ String
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/libssh_ruby/channel.c', line 220 static VALUE m_read(int argc, VALUE *argv, VALUE self) { ChannelHolder *holder; VALUE count, opts; const ID table[] = {id_stderr, id_timeout}; VALUE kwvals[sizeof(table) / sizeof(*table)]; struct nogvl_read_args args; VALUE ret; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); rb_scan_args(argc, argv, "10:", &count, &opts); Check_Type(count, T_FIXNUM); rb_get_kwargs(opts, table, 0, 2, kwvals); if (kwvals[0] == Qundef) { args.is_stderr = 0; } else { args.is_stderr = RTEST(kwvals[0]) ? 1 : 0; } if (kwvals[1] == Qundef) { args.timeout = -1; } else { Check_Type(kwvals[1], T_FIXNUM); args.timeout = FIX2INT(kwvals[1]); } args.channel = holder->channel; args.count = FIX2UINT(count); args.buf = ALLOC_N(char, args.count); rb_thread_call_without_gvl(nogvl_read, &args, RUBY_UBF_IO, NULL); ret = rb_utf8_str_new(args.buf, args.rc); ruby_xfree(args.buf); return ret; } |
#request_exec(cmd) ⇒ nil
156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/libssh_ruby/channel.c', line 156 static VALUE m_request_exec(VALUE self, VALUE cmd) { ChannelHolder *holder; struct nogvl_request_exec_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; args.cmd = StringValueCStr(cmd); rb_thread_call_without_gvl(nogvl_request_exec, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); return Qnil; } |
#request_pty ⇒ nil
182 183 184 185 186 187 188 189 190 191 |
# File 'ext/libssh_ruby/channel.c', line 182 static VALUE m_request_pty(VALUE self) { ChannelHolder *holder; struct nogvl_channel_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_request_pty, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); return Qnil; } |
#send_eof ⇒ nil
406 407 408 409 410 411 412 413 414 415 |
# File 'ext/libssh_ruby/channel.c', line 406 static VALUE m_send_eof(VALUE self) { ChannelHolder *holder; struct nogvl_channel_args args; TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; rb_thread_call_without_gvl(nogvl_send_eof, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); return Qnil; } |
#write(data) ⇒ Fixnum
378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'ext/libssh_ruby/channel.c', line 378 static VALUE m_write(VALUE self, VALUE data) { ChannelHolder *holder; struct nogvl_write_args args; Check_Type(data, T_STRING); TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder); args.channel = holder->channel; args.data = RSTRING_PTR(data); args.len = RSTRING_LEN(data); rb_thread_call_without_gvl(nogvl_write, &args, RUBY_UBF_IO, NULL); RAISE_IF_ERROR(args.rc); return INT2FIX(args.rc); } |