[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Working on keepalive messages while waiting for local connection


On Saturday, 14 April 2018 15:55:20 CEST g4-lisz@xxxxxxxxxxxx wrote:
> On 11.04.2018 18:09, g4-lisz@xxxxxxxxxxxx wrote:
> > On 11.04.2018 17:31, Andreas Schneider wrote:
> >> ould appreciate a lot if someone could show me some sample code.
> >> I think that ssh_event_dopoll() will handle it and call the appropriate
> >> callback. Don't use ssh_select()
> >> 
> >> In master we have the new connector API which is easier to use, see
> >> https://git.libssh.org/projects/libssh.git/tree/examples/ssh_client.c
> > 
> > Thanks, I think that's the issue: The main event polling is not called
> > why my code waits for a connection. But how do I get the event to which
> > are attached the default handlers of libssh?
> > 
> > I also looked at the sample code which uses the event API for polling on
> > the channel. But this would not solve my issue with global keep-alive
> > requests. They are sent while no channel exists. IMHO it's an issue with
> > handling messages in the main loop while no channels are open.
> 
> Well, maybe I should ask it this way:
> 
> How can I keep the internal main loop running, i.e. the default
> callbacks being triggered, when nothing else is going on?

You need to call of of the ssh poll functions, e.g. ssh_channel_poll() or 
ssh_event_dopoll() this will also trigger the standard callbacks if something 
is in the queue.

> What I needed is some ssh_handleMessages() function which I could call
> in the listening TCP socket select loop.
> 
> The only way I found to make it work is by sending some dummy message
> with ssh_send_ignore():
> 
>         while (1) {
>             FD_ZERO(&fds);
>             FD_SET(listensock, &fds);
>             tv.tv_sec = 5;
>             tv.tv_usec = 0;
>             sout_len = 0;
>            
>             rc = select(listensock+1, &fds, NULL, NULL, &tv);
>             if (-1 == rc && EINTR == errno)
>                 continue;
>             else if (0 < rc) {
>                 if (FD_ISSET(listensock, &fds)) {
>                     forwardsock = accept(listensock, NULL, &sout_len);
>                     if (forwardsock < 0) {
>                         perror("accept failed");
>                         goto shutdown;
>                     }
>                     else {
>                         printf("Local client connected.\n");
>                         break;
>                     }
>                 }
>             }
>             else if (0 > rc) {
>                 perror("waiting on listening socket");
>                 goto shutdown;
>             }
>             printf("Poll.\n");
>             ssh_send_ignore(session, "Say hello");
>         }
> 
>         channel = ssh_channel_new(session);
>         ssh_channel_open_forward( ...);


-- 
Andreas Schneider                   GPG-ID: CC014E3D
www.cryptomilk.org                asn@xxxxxxxxxxxxxx



Archive administrator: postmaster@lists.cynapses.org