Page MenuHomePhabricator

Move Constructors / Move Assignment for C++ Wrappers Session and Channel
Open, WishlistPublic

Description

Move Constructor of Channel and Session would allow to store them in standard containers. The implementation is trivial, but they should only be activated in C++ >= 11.

Sketch/Example for possible implementation:

Session::Session(Session && other) noexcept : 
  c_session()
{
  ::std::swap(c_session, other.c_session);
}

Session::~Session() noexcept
{
  if (c_session)
  {   
     ::ssh_free(c_session);
     c_session = nullptr;
  }
}

Channel::Channel(Channel && other) noexcept : session(), channel()
{
  using ::std::swap;
  swap(session, other.session);
  swap(channel, other.channel);
}

Channel::~Channel() noexcept 
{
  if (channel)
  {
     ::ssh_channel_free(channel);
     channel=nullptr;
  }
}

Event Timeline

cocus triaged this task as Wishlist priority.Dec 10 2019, 5:20 PM
cocus created this task.
Jakuje added a project: Restricted Project.Tue, Sep 22, 4:56 PM
Jakuje added a subscriber: Jakuje.

We are not primarily C++ developers so the C++ wrapper is the minimal support we could provide. If you know how to do this in sensible way, submitting a pull request with the patch (ideally also with demonstration in examples) would be the simplest way how to get this in.

https://gitlab.com/libssh/libssh-mirror