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

Working on keepalive messages while waiting for local connection


Hi there

I wrote some basic ssh client to forward a port. This involves binding a
local listening socket and waiting for an application to connect. But as
long as there is nothing connected to the local socket, the client is
not reading from or writing to the channel. This seems to be an issue as
soon as a SSH server sends keep alive messages: Because nothing is read
from the client's side of the channel, libssh does not work on the
keepalive messages.

The pseudo code looks like this:

socket = socket(PF_INET,...);
bind(socket);
listen(socket);

while(1) {
    do{ /* nada */ } while(  0 == select(socket,...) );
   
    forwardsock = accept(socket);
    channel = ssh_channel_new(session);
    ssh_channel_open_forward(channel, ...);

    while(1) {
        do{ /* nada */ } while( SSH_EINTR == ssh_select(channel,
channelout,  forwardsock) );

        if (FD_ISSET(forwardsock,...)) { /* read from socket and write
to channel */ }

        if (channelout) { /* read from channel and write to socket */ }

        if (EOF) {break;}
    }
    close(forwardsock);
    ssh_channel_close(channel);
}

Without keepalive messages from the server, all works fine.

How can this issue be solved?

Thanks,
Till



Archive administrator: postmaster@lists.cynapses.org