Hi,
I've started using libssh2, but I'm having a problem with receiving
intermediate results from an application. I use libssh2 on a Windows
client, connect to a Linux or AIX server (the problem occurs on either),
run an application on the server by sending a command line with
libssh2_channel_write, then start reading both stdout and stderr with
libssh2_channel_read and libssh2_channel_read_stderr (non-blocking on both).
The app on the server dribbles out information on stderr over a period
of 45 seconds, then exits. But my calls to libssh2_channel_read_stderr
return nothing until the server app exits - and then I quickly get all
the data that had been sent.
I've tried setting the socket's TCP_NODELAY but the problem persists. Is
there something I'm missing?
Basically, my simplified code is:
WSAStartup(WINSOCK_VERSION, &wsadata);
addrinfo aiHints = {0};
aiHints.ai_family = AF_INET;
aiHints.ai_socktype = SOCK_STREAM;
aiHints.ai_protocol = IPPROTO_TCP;
// Call getaddrinfo(). If the call succeeds, paiList will hold a linked list
// of addrinfo structures containing response information about the host.
addrinfo *paiList = NULL;
if (getaddrinfo(host, "22", &aiHints, &paiList) == 0)
{
// Create socket and establish connection
m_socket = socket(AF_INET, SOCK_STREAM, 0);
BOOL on = TRUE;
setsockopt(m_socket, IPPROTO_TCP, TCP_NODELAY, (const char *) &on,
sizeof(on));
connect(m_socket, paiList->ai_addr,
static_cast<int>(paiList->ai_addrlen));
m_session = libssh2_session_init_ex(&Malloc, &Free, &Realloc, NULL);
libssh2_session_startup(m_session, 0);
libssh2_userauth_keyboard_interactive_ex(m_session, userName,
(unsigned int) strlen(userName), &SKeyboardAuthCallback);
m_channel = libssh2_channel_open_session(session);
libssh2_channel_set_blocking(m_channel, 1);
libssh2_channel_shell(m_channel);
libssh2_channel_write(m_channel, "testprogram\n", 12);
while (1)
{
char buf[1000];
int len = libssh2_channel_read(m_channel, buf, 999);
buf[len] = '\0';
fputs(buf, stdout);
len = libssh2_channel_read_stderr(m_channel, buf, 999);
buf[len] = '\0';
fputs(buf, stderr);
}
I'd appreciate any help you can give.
Thank you,
Bob
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2009-03-23