From a2f93579b704fb1c2b56cf93e9a4da84e0cecf05 Mon Sep 17 00:00:00 2001 From: Eshan Kelkar Date: Sat, 24 May 2025 01:56:40 +0530 Subject: [PATCH] libssh: Use sftp_aio instead of sftp_async for sftp_recv This commit replaces the usage of the old deprecated sftp_async API with the new sftp_aio API for remote file reading. Signed-off-by: Eshan Kelkar --- lib/vssh/libssh.c | 23 +++++++++++++++++++++++ lib/vssh/ssh.h | 5 ++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c index d8e03e7ab1..e5b8de6017 100644 --- a/lib/vssh/libssh.c +++ b/lib/vssh/libssh.c @@ -1464,6 +1464,11 @@ static int myssh_in_SFTP_SHUTDOWN(struct Curl_easy *data, sftp_aio_free(sshc->sftp_send_aio); sshc->sftp_send_aio = NULL; } + + if(sshc->sftp_recv_aio) { + sftp_aio_free(sshc->sftp_recv_aio); + sshc->sftp_recv_aio = NULL; + } #endif if(sshc->sftp_file) { @@ -3101,16 +3106,28 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, switch(sshc->sftp_recv_state) { case 0: +#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) + if(sftp_aio_begin_read(sshc->sftp_file, len, + &sshc->sftp_recv_aio) == SSH_ERROR) { + return CURLE_RECV_ERROR; + } +#else sshc->sftp_file_index = sftp_async_read_begin(sshc->sftp_file, (uint32_t)len); if(sshc->sftp_file_index < 0) return CURLE_RECV_ERROR; +#endif FALLTHROUGH(); case 1: sshc->sftp_recv_state = 1; + +#if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) + nread = sftp_aio_wait_read(&sshc->sftp_recv_aio, mem, len); +#else nread = sftp_async_read(sshc->sftp_file, mem, (uint32_t)len, (uint32_t)sshc->sftp_file_index); +#endif myssh_block2waitfor(conn, sshc, (nread == SSH_AGAIN)); @@ -3119,6 +3136,12 @@ static CURLcode sftp_recv(struct Curl_easy *data, int sockindex, else if(nread < 0) return CURLE_RECV_ERROR; + /* + * sftp_aio_wait_read() would free sftp_recv_aio and + * assign it NULL in all cases except when it returns + * SSH_AGAIN. + */ + sshc->sftp_recv_state = 0; *pnread = (size_t)nread; return CURLE_OK; diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h index 89bc051c7c..3a29927e8c 100644 --- a/lib/vssh/ssh.h +++ b/lib/vssh/ssh.h @@ -180,10 +180,13 @@ struct ssh_conn { unsigned sftp_recv_state; /* 0 or 1 */ #if LIBSSH_VERSION_INT > SSH_VERSION_INT(0, 11, 0) + sftp_aio sftp_recv_aio; + sftp_aio sftp_send_aio; unsigned sftp_send_state; /* 0 or 1 */ -#endif +#else int sftp_file_index; /* for async read */ +#endif sftp_attributes readdir_attrs; /* used by the SFTP readdir actions */ sftp_attributes readdir_link_attrs; /* used by the SFTP readdir actions */ sftp_attributes quote_attrs; /* used by the SFTP_QUOTE state */