aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/libssh.h1
-rw-r--r--include/libssh/socket.h1
-rw-r--r--src/session.c25
-rw-r--r--src/socket.c12
4 files changed, 39 insertions, 0 deletions
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
index 504aac92..268d4292 100644
--- a/include/libssh/libssh.h
+++ b/include/libssh/libssh.h
@@ -324,6 +324,7 @@ enum ssh_scp_request_types {
SSH_SCP_REQUEST_WARNING
};
+LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout);
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
LIBSSH_API int ssh_channel_close(ssh_channel channel);
diff --git a/include/libssh/socket.h b/include/libssh/socket.h
index 625dc1c3..527f52ed 100644
--- a/include/libssh/socket.h
+++ b/include/libssh/socket.h
@@ -53,6 +53,7 @@ void ssh_socket_set_write_wontblock(ssh_socket s);
void ssh_socket_set_read_wontblock(ssh_socket s);
void ssh_socket_set_except(ssh_socket s);
int ssh_socket_get_status(ssh_socket s);
+int ssh_socket_buffered_write_bytes(ssh_socket s);
int ssh_socket_data_available(ssh_socket s);
int ssh_socket_data_writable(ssh_socket s);
diff --git a/src/session.c b/src/session.c
index ab7cdff9..be428889 100644
--- a/src/session.c
+++ b/src/session.c
@@ -298,6 +298,31 @@ int ssh_is_blocking(ssh_session session){
}
/**
+ * @brief Blocking flush of the outgoing buffer
+ * @param[in] session The SSH session
+ * @param[in] timeout Set an upper limit on the time for which this function
+ * will block, in milliseconds. Specifying a negative value
+ * means an infinite timeout. This parameter is passed to
+ * the poll() function.
+ * @returns SSH_OK on success, SSH_ERROR otherwise.
+ */
+
+int ssh_blocking_flush(ssh_session session, int timeout){
+ ssh_socket s;
+ if(session==NULL)
+ return SSH_ERROR;
+
+ enter_function();
+ s=session->socket;
+ while (ssh_socket_buffered_write_bytes(s) > 0 && session->alive) {
+ ssh_handle_packets(session, timeout);
+ }
+
+ leave_function();
+ return SSH_OK;
+}
+
+/**
* @brief Check if we are connected.
*
* @param[in] session The session to check if it is connected.
diff --git a/src/socket.c b/src/socket.c
index 0f8fc23c..24616255 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -644,6 +644,18 @@ int ssh_socket_data_writable(ssh_socket s) {
return s->write_wontblock;
}
+/** @internal
+ * @brief returns the number of outgoing bytes currently buffered
+ * @param s the socket
+ * @returns numbers of bytes buffered, or 0 if the socket isn't connected
+ */
+int ssh_socket_buffered_write_bytes(ssh_socket s){
+ if(s==NULL || s->out_buffer == NULL)
+ return 0;
+ return buffer_get_rest_len(s->out_buffer);
+}
+
+
int ssh_socket_get_status(ssh_socket s) {
int r = 0;