Esempio n. 1
0
/*
 * @overload poll(is_stderr: false, timeout: -1)
 *  Poll a channel for data to read.
 *  @since 0.1.0
 *  @param [Boolean] is_stderr A boolean to select the stderr stream.
 *  @param [Fixnum] timeout A timeout in milliseconds. A negative value means an
 *    infinite timeout.
 *  @return [Fixnum, nil] The number of bytes available for reading. +nil+ if
 *    timed out.
 *  @see http://api.libssh.org/stable/group__libssh__channel.html
 *    ssh_channel_poll_timeout
 */
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);
  }
}
Esempio n. 2
0
/*
 * @overload send_eof
 *  Send EOF on the channel.
 *  @since 0.1.0
 *  @return [nil]
 *  @see http://api.libssh.org/stable/group__libssh__channel.html
 *    ssh_channel_send_eof
 */
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;
}
Esempio n. 3
0
/*
 * @overload request_exec(cmd)
 *  Run a shell command without an interactive shell.
 *  @since 0.1.0
 *  @param [String] cmd The command to execute
 *  @return [nil]
 *  @see http://api.libssh.org/stable/group__libssh__channel.html
 *    ssh_channel_request_exec
 */
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;
}
Esempio n. 4
0
/*
 * @overload write(data)
 *  Write data on the channel.
 *  @since 0.1.0
 *  @param [String] data Data to write.
 *  @return [Fixnum] The number of bytes written.
 *  @see http://api.libssh.org/stable/group__libssh__channel.html
 *    ssh_channel_write
 */
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);
}
Esempio n. 5
0
/*
 * @overload open_session
 *  Open a session channel, and close it after the block.
 *  @since 0.1.0
 *  @yieldparam [Channel] channel self
 *  @return [Object] Return value of the block
 *  @see http://api.libssh.org/stable/group__libssh__channel.html
 *    ssh_channel_open_session
 */
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;
  }
}
Esempio n. 6
0
void FTP_Request::SetUserNameAndPassword(const OpStringC8 &usr_name, OpStringS8 &passwd)
{
	RAISE_IF_ERROR(username.Set(usr_name));
	password.OpStringS8::TakeOver(passwd);
}