Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions libssh2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ def set_trace(self, bitmask):
"""
self._session.set_trace(bitmask)

def keepalive_config(self, wantReply, interval):
"""
Set how often to send keepalives.

@param wantReply: Whether to request the server sends responses to keepalives
@type wantReply: bool
@param interval: How often to send keepalives (0 to disable)
@type interval: int
@param bitmask: bitmask on libssh2.LIBSSH2_TRACE_* constant
"""
self._session.keepalive_config(wantReply, interval)

def keepalive_send(self):
"""
Sends keepalive, if due. Call this to send keepalives from non-blocking code.

@return: seconds until next keepalive
@rtype: int
"""
return self._session.keepalive_send()

def scp_recv(self, remote_path):
"""
Expand Down
58 changes: 58 additions & 0 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,62 @@ PYLIBSSH2_Session_set_trace(PYLIBSSH2_SESSION *self, PyObject *args)
}
/* }}} */

/* PYLIBSSH2_Session_keepalive_config
*/
static char PYLIBSSH2_Session_keepalive_config_doc[] = "\n\
keepalive_config(want_reply, interval)\n\
\n\
Configures how often keepalives are sent.\n\
\n\
@param want_reply: keepalives request response from server\n\
@type want_reply: bool\n\
@param interval: time between keepalives (0 to disable)\n\
@type interval: int\n\
\n\
@return\n\
@rtype ";

static PyObject *
PYLIBSSH2_Session_keepalive_config(PYLIBSSH2_SESSION *self, PyObject *args)
{
int rc=0;
int want_reply, interval;

if (!PyArg_ParseTuple(args, "ii:keepalive_config", &want_reply, &interval)) {
return NULL;
}

Py_BEGIN_ALLOW_THREADS
libssh2_keepalive_config(self->session, want_reply, interval);
Py_END_ALLOW_THREADS

return Py_BuildValue("i", rc);
}
/* }}} */

/* PYLIBSSH2_Session_keepalive_send
*/
static char PYLIBSSH2_Session_keepalive_send_doc[] = "\n\
keepalive_send()\n\
\n\
Send keepalives if due when using non-blocking I/O.\n\
\n\
@return seconds until next keepalive\n\
@rtype int";

static PyObject *
PYLIBSSH2_Session_keepalive_send(PYLIBSSH2_SESSION *self, PyObject *args)
{
int rc=0;

Py_BEGIN_ALLOW_THREADS
libssh2_keepalive_send(self->session, &rc);
Py_END_ALLOW_THREADS

return Py_BuildValue("i", rc);
}
/* }}} */

/*
void
kbd_callback(const char *name, int name_len, const char *instruction,
Expand Down Expand Up @@ -1059,6 +1115,8 @@ static PyMethodDef PYLIBSSH2_Session_methods[] =
ADD_METHOD(last_error),
ADD_METHOD(callback_set),
ADD_METHOD(set_trace),
ADD_METHOD(keepalive_config),
ADD_METHOD(keepalive_send),
ADD_METHOD(userauth_keyboardinteractive),
ADD_METHOD(userauth_agent),
{ NULL, NULL }
Expand Down