Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Session object from sftp handle #15

Open
aaloksood opened this issue Oct 12, 2012 · 1 comment
Open

Accessing Session object from sftp handle #15

aaloksood opened this issue Oct 12, 2012 · 1 comment

Comments

@aaloksood
Copy link
Contributor

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.

@aaloksood
Copy link
Contributor Author

I have also tried this:

channel = libssh2_sftp_get_channel(self->sftp);
if (libssh2_session_last_error(channel->session, NULL, NULL, 0) ==
LIBSSH2_ERROR_EAGAIN){

This also fails to compile with error:
src/sftp.c:276:45: error: dereferencing pointer to incomplete type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant