[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: asynchronous channel write
  [Thread Prev] | [Thread Next]
 
 
- Subject: Re: asynchronous channel write
 - From: g4-lisz@xxxxxxxxxxxx
 - Reply-to: libssh@xxxxxxxxxx
 - Date: Mon, 13 Jan 2020 21:34:37 +0100
 - To: libssh@xxxxxxxxxx
 
Hi Torsten,
the "trick" is called ssh_set_blocking(session, 0);
But be careful, this affects everything in the session.
My write loop looks lile this:
    blocking = ssh_is_blocking(session);
    ssh_set_blocking(session, 0);
    if (len > 0) {
        if (ssh_channel_is_open(channel)) {
            wr = 0;
            do {
                i = ssh_channel_write(channel, buf, len);
                if (i < 0) {
                    log("Error writing on the direct-tcpip channel: %d", i);
                    len = wr;
                    break;
                }
                wr += i;
                log("channel_write (%d from %d)", wr, len);
            } while (i > 0 && wr < len);
        }
        else {
            log("Can't write on closed channel!");
        }
    }
    ssh_set_blocking(session, blocking);
Greetings,
Till
On 13.01.20 17:48, Torsten Kuehnel wrote:
> Working on the reference implementation of the ncot library i am
> confronted with the follwoing use case:
>
> Data packets are to be received and send from/to several simultaneous
> open ssh-like encrypted channels to instances of the same program
> running on other hosts over the network.
>
> The one client-server connection -> one thread paradigm does not fit
> so well. Packets have to be validated, act upon and processed in
> different ways, and need to be resend to other connections - this is
> the real part of the implementation.
>
> So my approach currently is the following one:
>
> A mainloop with ssh_event_dopoll manages to call my channel callbacks
> i have established during initialization of the several sessions. But
> when it comes to write my packets over the channels, libssh only offers
> a blocking ssh_channel_write call what is not what i want.
>
> When the poll returns with write possible, i usually try to write as
> much as i can and send tells me how much succeded. How can i achieve
> this behaviour using libssh ?
>
> thanks for any insights in advance, keep up the good work !
>
> -- Torsten Kuehnel
> <tdkuehnel@xxxxxxxxxxxxxxxxxxxxx>
>
| Re: asynchronous channel write | Torsten Kuehnel <tdkuehnel@xxxxxxxxxxxxxxxxxxxxx> | 
| asynchronous channel write | Torsten Kuehnel <tdkuehnel@xxxxxxxxxxxxxxxxxxxxx> |