Skip to content

Accessing Session object from sftp handle #15

@aaloksood

Description

@aaloksood

I am building non-blocking sftp support for pylibssh2.

It works just fine except for one thing. When I do a sftp.open or sftp.opendir in non blocking mode, I have to call libssh2_session_last_error to see if this was a EGAIN or some genuine error.

I was not able to access session object from the sftp object in the sftp handle.

I have however worked around this problem by keeping pointer to session object in sftp handle.
Now on my local, sftp works beautifully in non blocking mode.

This is what the code for opendir looks like:

    Py_BEGIN_ALLOW_THREADS
    handle = libssh2_sftp_opendir(self->sftp, path);
    Py_END_ALLOW_THREADS

    if (handle == NULL) {
      if (libssh2_session_last_error(self->session, NULL, NULL, 0) ==
      LIBSSH2_ERROR_EAGAIN){
    return Py_BuildValue("");
      }
      else{
        /* CLEAN: PYLIBSSH2_SFTPHANDLE_CANT_OPENDIR_MSG */
        PyErr_SetString(PYLIBSSH2_Error, "Unable to open sftp directory.");
        return NULL;
      }
    }

Before I send in a merge request, I wanted to make sure if this approach is okay, or if there are other (better) ways to do this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions