Rewrote channel_read_buffer to use ssh_channel_read
Этот коммит содержится в:
родитель
c4e67730a3
Коммит
985db35173
107
src/channels.c
107
src/channels.c
@ -1984,86 +1984,51 @@ error:
|
|||||||
int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
|
||||||
int is_stderr) {
|
int is_stderr) {
|
||||||
ssh_session session=channel->session;
|
ssh_session session=channel->session;
|
||||||
ssh_buffer stdbuf = channel->stdout_buffer;
|
char buffer_tmp[8192];
|
||||||
uint32_t maxread = count;
|
int r;
|
||||||
uint32_t len;
|
uint32_t total=0;
|
||||||
|
|
||||||
buffer_reinit(buffer);
|
|
||||||
|
|
||||||
enter_function();
|
enter_function();
|
||||||
|
buffer_reinit(buffer);
|
||||||
if (count == 0) {
|
if(count==0){
|
||||||
maxread = MAX_PACKET_LEN;
|
do {
|
||||||
|
r=ssh_channel_poll(channel, is_stderr);
|
||||||
|
if(r < 0){
|
||||||
|
leave_function();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if(r > 0){
|
||||||
|
r=ssh_channel_read(channel, buffer_tmp, r, is_stderr);
|
||||||
|
if(r < 0){
|
||||||
|
leave_function();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
buffer_add_data(buffer,buffer_tmp,r);
|
||||||
|
leave_function();
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
if(ssh_channel_is_eof(channel)){
|
||||||
|
leave_function();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ssh_handle_packets(channel->session, -1);
|
||||||
|
} while (r == 0);
|
||||||
}
|
}
|
||||||
|
while(total < count){
|
||||||
if (is_stderr) {
|
r=ssh_channel_read(channel, buffer_tmp, sizeof(buffer_tmp), is_stderr);
|
||||||
stdbuf = channel->stderr_buffer;
|
if(r<0){
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We may have problem if the window is too small to accept as much data
|
|
||||||
* as asked
|
|
||||||
*/
|
|
||||||
ssh_log(session, SSH_LOG_PROTOCOL,
|
|
||||||
"Read (%d) buffered: %d bytes. Window: %d",
|
|
||||||
count,
|
|
||||||
buffer_get_rest_len(stdbuf),
|
|
||||||
channel->local_window);
|
|
||||||
|
|
||||||
if (count > buffer_get_rest_len(stdbuf) + channel->local_window) {
|
|
||||||
if (grow_window(session, channel, count) < 0) {
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return -1;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
if(r==0){
|
||||||
/* block reading if asked bytes=0 */
|
|
||||||
while (buffer_get_rest_len(stdbuf) == 0 ||
|
|
||||||
buffer_get_rest_len(stdbuf) < count) {
|
|
||||||
if (channel->remote_eof && buffer_get_rest_len(stdbuf) == 0) {
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return 0;
|
return total;
|
||||||
}
|
}
|
||||||
if (channel->remote_eof) {
|
buffer_add_data(buffer,buffer_tmp,r);
|
||||||
/* Return the resting bytes in buffer */
|
total += r;
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (buffer_get_rest_len(stdbuf) >= maxread) {
|
|
||||||
/* Stop reading when buffer is full enough */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ssh_handle_packets(session,-1);
|
|
||||||
}
|
}
|
||||||
/* XXX This is probably not the good moment to increase the window,
|
|
||||||
* but since the function is deprecated I won't fix it
|
|
||||||
*/
|
|
||||||
if(channel->local_window < WINDOWLIMIT) {
|
|
||||||
if (grow_window(session, channel, 0) < 0) {
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0) {
|
|
||||||
/* write the ful buffer information */
|
|
||||||
if (buffer_add_data(buffer, buffer_get_rest(stdbuf),
|
|
||||||
buffer_get_rest_len(stdbuf)) < 0) {
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
buffer_reinit(stdbuf);
|
|
||||||
} else {
|
|
||||||
/* Read bytes bytes if len is greater, everything otherwise */
|
|
||||||
len = buffer_get_rest_len(stdbuf);
|
|
||||||
len = (len > count ? count : len);
|
|
||||||
if (buffer_add_data(buffer, buffer_get_rest(stdbuf), len) < 0) {
|
|
||||||
leave_function();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
buffer_pass_bytes(stdbuf,len);
|
|
||||||
}
|
|
||||||
|
|
||||||
leave_function();
|
leave_function();
|
||||||
return ssh_buffer_get_len(buffer);
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO FIXME Fix the delayed close thing */
|
/* TODO FIXME Fix the delayed close thing */
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user