Ticket #21 (closed defect)

Opened 11 years ago

Last modified 8 years ago

libssh2_poll_channel_read()

Reported by: cnystrom Owned by: bagder
Priority: low Milestone:
Component: Version:
Keywords: Cc: cnystrom, bagder, jehousley
Blocked By: Blocks:

Description

I believe the following code demonstrates a bug with
the function libssh2_poll_channel_read(). This function
should return 1 when data is waiting to be read, but
always seems to return 0. In the program below I get a
return of zero, but I immediately and successfully read
data.

I need this function to work properly so I can write a
wrapper over libssh2 so I can use it in a
multi-threaded application.

Chris

--

#include "ssh2_lib.h"
#include <stdio.h>
#include "../sock_lib/sock_lib.h"

#define SSH_PORT (22)

int main(int argc, char *argv[])
{

int sock;
char buf[256] = "";
LIBSSH2_SESSION *session;
LIBSSH2_CHANNEL *channel;

const char *server = "apollo.newio.org";
const char *username = "cnystrom";
const char *passwd = "";

sock = init_tcp_client(server, SSH_PORT);

if (sock <= 0) {

return (-1);

}

session = libssh2_session_init();

if (libssh2_session_startup(session, sock)) {

fprintf(stderr, "Failure establishing

SSH session\n");

return(-3);

}

if (libssh2_userauth_password(session, username,

passwd)) {

fprintf(stderr, "Authentication by

password failed.\n");

return (-4);

}

if (!(channel =

libssh2_channel_open_session(session))) {

fprintf(stderr, "Unable to open a

channel\n");

return (-5);

}

libssh2_channel_set_blocking(channel, BLOCK);

if (libssh2_channel_subsystem(channel, "hello")

!= 0) {

fprintf(stderr,

"error:

libssh2_channel_subsystem() failed.\n");

return (-6);

}

int i;

bug: should return 1, but returns 0
i = libssh2_poll_channel_read(channel, 0);

printf("i = %d\n", i);

libssh2_channel_read(channel, buf, 256);

printf("--\n");
printf("%s", buf);
printf("--\n");

libssh2_channel_free(channel);

libssh2_session_disconnect(session, "Normal

Shutdown.");

libssh2_session_free(session);

close_socket(sock);

return 0;

}

Change History

comment:1 Changed 10 years ago by jehousley

Looking at the code, that is correct. The code loops looking at the same packet over and over. There needs to be a call of some type to libssh2_packet_read(), otherwise nothing will ever change in a single threaded program.

comment:2 Changed 8 years ago by bagder

What exactly are you using/needing this function for? I don't see its purpose. I would rather like to just deprecate it and not care about it anymore...

Note: See TracTickets for help on using tickets.