mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-08 19:02:06 +03:00
channels: Add a ssh_channel_read_timeout function.
This commit is contained in:
@@ -377,6 +377,7 @@ LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr,
|
|||||||
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
|
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
|
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
|
||||||
|
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout);
|
||||||
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
|
||||||
int is_stderr);
|
int is_stderr);
|
||||||
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
|
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
|
||||||
|
@@ -2670,7 +2670,40 @@ static int ssh_channel_read_termination(void *s){
|
|||||||
* @warning The read function using a buffer has been renamed to
|
* @warning The read function using a buffer has been renamed to
|
||||||
* channel_read_buffer().
|
* channel_read_buffer().
|
||||||
*/
|
*/
|
||||||
int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr) {
|
int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr)
|
||||||
|
{
|
||||||
|
return ssh_channel_read_timeout(channel, dest, count, is_stderr, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads data from a channel.
|
||||||
|
*
|
||||||
|
* @param[in] channel The channel to read from.
|
||||||
|
*
|
||||||
|
* @param[in] dest The destination buffer which will get the data.
|
||||||
|
*
|
||||||
|
* @param[in] count The count of bytes to be read.
|
||||||
|
*
|
||||||
|
* @param[in] is_stderr A boolean value to mark reading from the stderr flow.
|
||||||
|
*
|
||||||
|
* @param[in] timeout A timeout in seconds. A value of -1 means infinite
|
||||||
|
* timeout.
|
||||||
|
*
|
||||||
|
* @return The number of bytes read, 0 on end of file or SSH_ERROR
|
||||||
|
* on error. In nonblocking mode it Can return 0 if no data
|
||||||
|
* is available or SSH_AGAIN.
|
||||||
|
*
|
||||||
|
* @warning This function may return less than count bytes of data, and won't
|
||||||
|
* block until count bytes have been read.
|
||||||
|
* @warning The read function using a buffer has been renamed to
|
||||||
|
* channel_read_buffer().
|
||||||
|
*/
|
||||||
|
int ssh_channel_read_timeout(ssh_channel channel,
|
||||||
|
void *dest,
|
||||||
|
uint32_t count,
|
||||||
|
int is_stderr,
|
||||||
|
int timeout)
|
||||||
|
{
|
||||||
ssh_session session;
|
ssh_session session;
|
||||||
ssh_buffer stdbuf;
|
ssh_buffer stdbuf;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
@@ -2718,8 +2751,15 @@ int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_std
|
|||||||
ctx.channel = channel;
|
ctx.channel = channel;
|
||||||
ctx.buffer = stdbuf;
|
ctx.buffer = stdbuf;
|
||||||
ctx.count = 1;
|
ctx.count = 1;
|
||||||
rc = ssh_handle_packets_termination(session, SSH_TIMEOUT_DEFAULT,
|
|
||||||
ssh_channel_read_termination, &ctx);
|
if (timeout < 0) {
|
||||||
|
timeout = SSH_TIMEOUT_DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_handle_packets_termination(session,
|
||||||
|
timeout,
|
||||||
|
ssh_channel_read_termination,
|
||||||
|
&ctx);
|
||||||
if (rc == SSH_ERROR){
|
if (rc == SSH_ERROR){
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user