Subject: libssh2 and no wait I/O Example

libssh2 and no wait I/O Example

From: Phillip Wu <Phillip.Wu_at_lpma.nsw.gov.au>
Date: Fri, 20 Aug 2010 16:42:04 +1000

Does anyone have a simple example of how to use select with libssh2?

I have seen the example ssh2_exec.c but this is a bit confusing.

Is this the rough idea (read from a shell with timeout):
sock = socket(AF_INET, SOCK_STREAM, 0);

connect(sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)

session = libssh2_session_init();

rc = libssh2_session_startup(session, sock);

/* Authenticate */

/* Run shell */
rc = libssh2_channel_exec(channel, "/bin/sh")

   FD_ZERO(&fd);
   FD_SET(socket_fd, &fd);
  readfd = &fd;
/* Set non blocking */
libssh2_session_set_blocking(session, 0);

/* Read from shell */
rc = select(socket_fd + 1, readfd, writefd, NULL,&timeout);
libssh2_channel_read(channel,buf,sizeof(buf))

***************************************************************
This message is intended for the addressee named and may contain confidential information. If you are not the intended recipient, please delete it and notify the sender. Views expressed in this message are those of the individual sender, and are not necessarily the views of the Land and Property Management Authority. This email message has been swept by MIMEsweeper for the presence of computer viruses.
***************************************************************
Please consider the environment before printing this email.

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2010-08-20