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

Re: sftp_aio_wait_read() and SSH_AGAIN


Hi Edrusb,

is there a way to have a call to sftp_aio_wait_read() that never return
> SSH_AGAIN, but instead waits until the expected data is ready and then
> return it?


When the sftp_file is in blocking mode, sftp_aio_wait_read() should block
until it gets a response or encounters an error. (See
sftp_file_set_blocking() here
https://api.libssh.org/stable/group__libssh__sftp.html#gaaf4ec4504dfcf9b9c911684f1ab782a3
)

Or is there some reason (that I am overlooking) due to which this could not
be done in your case (or does not work ?) ?

Or, asked another way: when sftp_aio_wait_read() returns SSH_AGAIN, can
> a program call it again right away as there is no chance it returns
> again SSH_AGAIN and thus there is no need to wait/sleep for some time
> between calls in that context, to avoid wasting CPU cycles and creating
> unnecessary load on the system?


Yes, a program can call sftp_aio_wait_read() again right away after it
returns. However, when such blocking behaviour is needed, it is recommended
to use the aforementioned approach instead, i.e:

1. Open a sftp_file in blocking mode (default) or set to blocking mode
using sftp_file_set_blocking()
2. Call sftp_aio_wait_read() which should wait (or will report failure)
till expected data comes.

I take the opportunity of this question to thank you for libssh, its API
> (which is very easy to use) and the very clear documentation it has :)


Thank you for the kind words and using libssh !

Regards,
Eshan Kelkar


On Sat, Jul 26, 2025 at 3:28 AM Edrusb <lib.ssh@xxxxxxxxxx> wrote:

> Hi all,
>
> is there a way to have a call to sftp_aio_wait_read() that never return
> SSH_AGAIN, but instead waits until the expected data is ready and then
> return it?
>
> Or, asked another way: when sftp_aio_wait_read() returns SSH_AGAIN, can
> a program call it again right away as there is no chance it returns
> again SSH_AGAIN and thus there is no need to wait/sleep for some time
> between calls in that context, to avoid wasting CPU cycles and creating
> unnecessary load on the system?
>
> I take the opportunity of this question to thank you for libssh, its API
> (which is very easy to use) and the very clear documentation it has :)
>
> Edrusb
>
>
>
>
>

Archive administrator: postmaster@lists.cynapses.org