mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
Improve channel_poll() and add a SSH_EOF return value.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@702 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -147,10 +147,11 @@ typedef int socket_t;
|
|||||||
#define SSH_FATAL 2
|
#define SSH_FATAL 2
|
||||||
#define SSH_EINTR 3
|
#define SSH_EINTR 3
|
||||||
|
|
||||||
/* error return codes */
|
/* Error return codes */
|
||||||
#define SSH_OK 0 /* No error */
|
#define SSH_OK 0 /* No error */
|
||||||
#define SSH_ERROR -1 /* error of some kind */
|
#define SSH_ERROR -1 /* Error of some kind */
|
||||||
#define SSH_AGAIN -2 /* the nonblocking call must be repeated */
|
#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
|
||||||
|
#define SSH_EOF -127 /* We have already a eof */
|
||||||
|
|
||||||
const char *ssh_get_error(void *error);
|
const char *ssh_get_error(void *error);
|
||||||
int ssh_get_error_code(void *error);
|
int ssh_get_error_code(void *error);
|
||||||
|
|||||||
@@ -1582,36 +1582,44 @@ int channel_read_nonblocking(CHANNEL *channel, void *dest, u32 count,
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief polls the channel for data to read
|
/**
|
||||||
* \param channel channel
|
* @brief Polls a channel for data to read.
|
||||||
* \param is_stderr boolean to select the stderr stream
|
*
|
||||||
* \return number of bytes available for reading\n
|
* @param channel The channel to poll.
|
||||||
* 0 if nothing is available\n
|
*
|
||||||
* SSH_ERROR on error
|
* @param is_stderr A boolean to select the stderr stream.
|
||||||
* \warning When the channel is in EOF state, the function returns 1
|
*
|
||||||
* \see channel_is_eof()
|
* @return The number of bytes available for reading, 0 if nothing is available
|
||||||
|
* or SSH_ERROR on error.
|
||||||
|
*
|
||||||
|
* @warning When the channel is in EOF state, the function returns SSH_EOF.
|
||||||
|
*
|
||||||
|
* @see channel_is_eof()
|
||||||
*/
|
*/
|
||||||
int channel_poll(CHANNEL *channel, int is_stderr){
|
int channel_poll(CHANNEL *channel, int is_stderr){
|
||||||
BUFFER *buffer;
|
|
||||||
SSH_SESSION *session = channel->session;
|
SSH_SESSION *session = channel->session;
|
||||||
int r=0;
|
BUFFER *stdbuf = channel->stdout_buffer;
|
||||||
enter_function();
|
int rc;
|
||||||
if(is_stderr)
|
|
||||||
buffer=channel->stderr_buffer;
|
|
||||||
else
|
|
||||||
buffer=channel->stdout_buffer;
|
|
||||||
|
|
||||||
while(buffer_get_rest_len(buffer)==0 && !channel->remote_eof){
|
enter_function();
|
||||||
r=ssh_handle_packets(channel->session);
|
|
||||||
if(r<=0)
|
if (is_stderr) {
|
||||||
|
stdbuf = channel->stderr_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (buffer_get_rest_len(stdbuf) == 0 && channel->remote_eof == 0) {
|
||||||
|
if (ssh_handle_packets(channel->session) < 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (channel->remote_eof) {
|
if (channel->remote_eof) {
|
||||||
leave_function();
|
leave_function();
|
||||||
return 1;
|
return SSH_EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return buffer_get_rest_len(buffer);
|
return buffer_get_rest_len(stdbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief recover the session in which belong a channel
|
/** \brief recover the session in which belong a channel
|
||||||
|
|||||||
Reference in New Issue
Block a user