aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2010-10-01 23:03:08 +0200
committerAris Adamantiadis <aris@0xbadc0de.be>2010-10-01 23:03:08 +0200
commit985db35173dcac8bd52cd453449e9b2f3b757d5b (patch)
tree0a21422e56163ea23e377b81573281cb08c51e96
parentc4e67730a3ac2c921420b068b7f72e0675a12c43 (diff)
downloadlibssh-985db35173dcac8bd52cd453449e9b2f3b757d5b.tar.gz
libssh-985db35173dcac8bd52cd453449e9b2f3b757d5b.tar.xz
libssh-985db35173dcac8bd52cd453449e9b2f3b757d5b.zip
Rewrote channel_read_buffer to use ssh_channel_read
-rw-r--r--src/channels.c107
1 files changed, 36 insertions, 71 deletions
diff --git a/src/channels.c b/src/channels.c
index 1826f5a..6bf8543 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -1984,86 +1984,51 @@ error:
int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
int is_stderr) {
ssh_session session=channel->session;
- ssh_buffer stdbuf = channel->stdout_buffer;
- uint32_t maxread = count;
- uint32_t len;
-
- buffer_reinit(buffer);
+ char buffer_tmp[8192];
+ int r;
+ uint32_t total=0;
enter_function();
-
- if (count == 0) {
- maxread = MAX_PACKET_LEN;
- }
-
- if (is_stderr) {
- stdbuf = channel->stderr_buffer;
- }
-
- /*
- * 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();
- return -1;
- }
- }
- /* 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();
- return 0;
- }
- if (channel->remote_eof) {
- /* Return the resting bytes in buffer */
- 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;
- }
+ buffer_reinit(buffer);
+ if(count==0){
+ 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);
}
-
- if (count == 0) {
- /* write the ful buffer information */
- if (buffer_add_data(buffer, buffer_get_rest(stdbuf),
- buffer_get_rest_len(stdbuf)) < 0) {
+ while(total < count){
+ r=ssh_channel_read(channel, buffer_tmp, sizeof(buffer_tmp), is_stderr);
+ if(r<0){
leave_function();
- return -1;
+ return r;
}
- 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) {
+ if(r==0){
leave_function();
- return -1;
+ return total;
}
- buffer_pass_bytes(stdbuf,len);
+ buffer_add_data(buffer,buffer_tmp,r);
+ total += r;
}
-
leave_function();
- return ssh_buffer_get_len(buffer);
+ return total;
}
/* TODO FIXME Fix the delayed close thing */