Subject: Re: internal poll doesn't handle orderly shut down (read/recv returns 0 bytes) = 100% CPU

Re: internal poll doesn't handle orderly shut down (read/recv returns 0 bytes) = 100% CPU

From: Pavel Strashkin <pavel.strashkin_at_gmail.com>
Date: Mon, 3 Oct 2011 11:20:16 -0700

file: src/session.c, function: libssh2_poll, with defined HAVE_POLL
(it uses poll instead of select)

==BEG==
1598 case LIBSSH2_POLLFD_SOCKET:
1599 fds[i].revents = sockets[i].revents;
1600 sockets[i].revents = 0; /* In case we loop
again, be nice */
1601 if (fds[i].revents) {
1602 active_fds++;
1603 }
1604 break;
1605 case LIBSSH2_POLLFD_CHANNEL:
1606 if (sockets[i].events & POLLIN) {
1607 /* Spin session until no data available */
1608 while
(_libssh2_transport_read(fds[i].fd.channel->session)
1609 > 0);
1610 }
1611 if (sockets[i].revents & POLLHUP) {
1612 fds[i].revents |=
1613 LIBSSH2_POLLFD_CHANNEL_CLOSED |
1614 LIBSSH2_POLLFD_SESSION_CLOSED;
1615 }
1616 sockets[i].revents = 0;
1617 break;
==END==

What it does, it goes to "case LIBSSH2_POLLFD_CHANNEL" branch because
i'm reading from a channel, does some work and doesn't increase
active_fds counter so do/while loop waits for N timeout.
In subject case the poll call always returns POLLIN event, but
read/recv call always returns 0.

2011/10/3 Daniel Stenberg <daniel_at_haxx.se>:
> On Mon, 3 Oct 2011, Pavel Strashkin wrote:
>
>> I'm working with libssh2 (the latest stable build) using Net::SSH2 Perl
>> binding. It uses internal libssh2 poll helper with a 250ms timeout.
>
> What is this "internal libssh2 poll helper" exactly?
>
> --
>
>  / daniel.haxx.se
> _______________________________________________
> libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
>

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-10-03