Subject: [libssh2] [ libssh2-Bugs-1841442 ] libssh2-0.18 session.c

[libssh2] [ libssh2-Bugs-1841442 ] libssh2-0.18 session.c

From: <>
Date: Mon, 03 Dec 2007 02:59:20 -0800

Bugs item #1841442, was opened at 2007-11-30 05:56
Message generated for change (Comment added) made by bagder
You can respond by visiting:

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: API
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Gary Miller (gmiller1018)
>Assigned to: Daniel Stenberg (bagder)
Summary: libssh2-0.18 session.c

Initial Comment:
I have noticed an issue with libssh2_poll on my Linux machines. I found that on my machines HAVE_POLL and HAVE_SELECT are defined and the code that is executed in the poll code not the select. I fixed this by just undef'ing the HAVE_POLL.

The other issue here is when the select code is enabled the code in the libssh2_poll seems to be in error. The code as I fixed it is:
        if (sysret > 0) {
            for(i = 0; i < nfds; i++) {
                switch (fds[i].type) {
                case LIBSSH2_POLLFD_SOCKET:
                    if (FD_ISSET(fds[i].fd.socket, &rfds)) {
                        fds[i].revents |= LIBSSH2_POLLFD_POLLIN;
                    if (FD_ISSET(fds[i].fd.socket, &wfds)) {
                        fds[i].revents |= LIBSSH2_POLLFD_POLLOUT;
                    if (fds[i].revents) {

                case LIBSSH2_POLLFD_CHANNEL:
                    if (FD_ISSET(fds[i]>session->socket_fd, &rfds)) {
                        /* Spin session until no data available */
                        //while (libssh2_packet_read(fds[i]>session)
                        // > 0);

                case LIBSSH2_POLLFD_LISTENER:
                    if (FD_ISSET
                        (fds[i].fd.listener->session->socket_fd, &rfds)) {
                        /* Spin session until no data available */
                        //while (libssh2_packet_read(fds[i].fd.listener->session)
                        // > 0);

when the FD_ISSET is true the code was looping reading (libssh2_packet_read) till and error occured but the behavio was reading till blocked. I changed the code to just read once (since that is all the FD_ISSET guaranteed). The increment of active_fds was also missing so the loop would not exit when it needs to.

There are still some cases where I think there is data but it is not being returned for some reason. I have not been able to identify the cause but I am working on it.

In my use of the poll function I am monitiring sockets of my own and sockets under control of libssh2 so my use may not be typical.

should there be some reason that my changes are breaking something and there is another way to fix this please let me know.


>Comment By: Daniel Stenberg (bagder)
Date: 2007-12-03 11:59

Logged In: YES
Originator: NO

Well of course it is a bug if it only works in non-blocking mode, as it is
supposed to always work. Personally I only use libssh2 non-blocking... So
just changing the docs isn't the proper fix.

The socket could of course be made non-blocking just for this loop...
Perhaps that is the best fix at least short-term?


Comment By: Gary Miller (gmiller1018)
Date: 2007-11-30 06:53

Logged In: YES
Originator: YES

It appears from my experimentation that the looping to read with the
libssh2_packet_read is needed so the ONLY way this code area will work is
if the sockets are made NON BLOCKING and the increment of the active_fds is
there. If this truly is a requirement then I would like to see the
documentation changed or the code check to see of the socket is in non
blocking mode and do something to indicate that this is a problem.


You can respond by visiting:

SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
libssh2-devel mailing list
Received on 2007-12-03