1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-07-31 00:03:08 +03:00

To simplify the user's error interface always use LIBSSH2_ERROR_EAGAIN.

LIBSSH2CHANNEL_EAGAIN and LIBSSH2SFTP_EAGAIN are still valid, but are
defined as LIBSSH2_ERROR_EAGAIN.
This commit is contained in:
James Housley
2007-06-08 13:33:08 +00:00
parent 281283d252
commit cf8f4d1818
17 changed files with 59 additions and 60 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: scp_nonblock.c,v 1.4 2007/06/06 12:34:08 jehousley Exp $
* $Id: scp_nonblock.c,v 1.5 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do SCP transfers in a non-blocking manner.
*/
@ -123,7 +123,7 @@ int main(int argc, char *argv[])
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) == LIBSSH2CHANNEL_EAGAIN);
password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
@ -174,7 +174,7 @@ int main(int argc, char *argv[])
}
} while (rc > 0);
if (rc == LIBSSH2CHANNEL_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
/* this is due to blocking that would occur otherwise
so we loop on this condition */

View File

@ -1,5 +1,5 @@
/*
* $Id: scp_write_nonblock.c,v 1.1 2007/06/06 12:34:08 jehousley Exp $
* $Id: scp_write_nonblock.c,v 1.2 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do a simple SCP transfer.
*/
@ -141,7 +141,7 @@ int main(int argc, char *argv[])
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
@ -151,7 +151,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) == LIBSSH2CHANNEL_EAGAIN);
password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
@ -181,7 +181,7 @@ int main(int argc, char *argv[])
do {
/* write data in a loop until we block */
while ((rc = libssh2_channel_write(channel, ptr, nread)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_channel_write(channel, ptr, nread)) == LIBSSH2_ERROR_EAGAIN);
if (rc < 0) {
fprintf(stderr, "ERROR %d\n", rc);
}
@ -191,23 +191,23 @@ int main(int argc, char *argv[])
} while (1);
fprintf(stderr, "Sending EOF\n");
while (libssh2_channel_send_eof(channel) == LIBSSH2CHANNEL_EAGAIN);
while (libssh2_channel_send_eof(channel) == LIBSSH2_ERROR_EAGAIN);
fprintf(stderr, "Waiting for EOF\n");
while (libssh2_channel_wait_eof(channel) == LIBSSH2CHANNEL_EAGAIN);
while (libssh2_channel_wait_eof(channel) == LIBSSH2_ERROR_EAGAIN);
fprintf(stderr, "Waiting for channel to close\n");
while (libssh2_channel_wait_closed(channel) == LIBSSH2CHANNEL_EAGAIN);
while (libssh2_channel_wait_closed(channel) == LIBSSH2_ERROR_EAGAIN);
// fprintf(stderr, "Closing channel\n");
// while (libssh2_channel_close(channel) == LIBSSH2CHANNEL_EAGAIN);
// while (libssh2_channel_close(channel) == LIBSSH2_ERROR_EAGAIN);
libssh2_channel_free(channel);
channel = NULL;
shutdown:
while ((rc = libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing")) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_session_disconnect(session, "Normal Shutdown, Thank you for playing")) == LIBSSH2_ERROR_EAGAIN);
libssh2_session_free(session);
#ifdef WIN32

View File

@ -1,5 +1,5 @@
/*
* $Id: sftp_RW_nonblock.c,v 1.6 2007/06/07 16:01:13 jehousley Exp $
* $Id: sftp_RW_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do SFTP transfers in a non-blocking manner.
*
@ -187,7 +187,7 @@ int main(int argc, char *argv[])
}
} while (rc > 0);
if(rc != LIBSSH2SFTP_EAGAIN) {
if(rc != LIBSSH2_ERROR_EAGAIN) {
/* error or end of file */
break;
}
@ -246,7 +246,7 @@ int main(int argc, char *argv[])
nread -= nread;
} while (rc > 0);
if(rc != LIBSSH2SFTP_EAGAIN) {
if(rc != LIBSSH2_ERROR_EAGAIN) {
/* error or end of file */
break;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: sftp_mkdir_nonblock.c,v 1.5 2007/06/07 16:01:13 jehousley Exp $
* $Id: sftp_mkdir_nonblock.c,v 1.6 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do SFTP non-blocking mkdir.
*
@ -156,7 +156,7 @@ int main(int argc, char *argv[])
LIBSSH2_SFTP_S_IRWXU|
LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IXGRP|
LIBSSH2_SFTP_S_IROTH|LIBSSH2_SFTP_S_IXOTH))
== LIBSSH2SFTP_EAGAIN) {
== LIBSSH2_ERROR_EAGAIN) {
;
}

View File

@ -1,5 +1,5 @@
/*
* $Id: sftp_nonblock.c,v 1.9 2007/06/07 16:01:13 jehousley Exp $
* $Id: sftp_nonblock.c,v 1.10 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do SFTP non-blocking transfers.
*
@ -129,7 +129,7 @@ int main(int argc, char *argv[])
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
@ -139,7 +139,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) == LIBSSH2CHANNEL_EAGAIN);
password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
@ -173,7 +173,7 @@ int main(int argc, char *argv[])
/* loop until we fail */
fprintf(stderr, "libssh2_sftp_readnb()!\n");
while ((rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem))) == LIBSSH2SFTP_EAGAIN) {
while ((rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem))) == LIBSSH2_ERROR_EAGAIN) {
;
}
if (rc > 0) {

View File

@ -1,5 +1,5 @@
/*
* $Id: sftp_write_nonblock.c,v 1.6 2007/06/07 16:01:14 jehousley Exp $
* $Id: sftp_write_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
*
* Sample showing how to do SFTP non-blocking write transfers.
*
@ -143,7 +143,7 @@ int main(int argc, char *argv[])
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("Authentication by password failed.\n");
goto shutdown;
@ -153,7 +153,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) == LIBSSH2CHANNEL_EAGAIN);
password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
printf("\tAuthentication by public key failed\n");
goto shutdown;
@ -199,7 +199,7 @@ int main(int argc, char *argv[])
do {
/* write data in a loop until we block */
while ((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) == LIBSSH2SFTP_EAGAIN) {
while ((rc = libssh2_sftp_write(sftp_handle, ptr, nread)) == LIBSSH2_ERROR_EAGAIN) {
;
}
ptr += rc;

View File

@ -1,5 +1,5 @@
/*
* $Id: sftpdir_nonblock.c,v 1.6 2007/06/07 16:01:14 jehousley Exp $
* $Id: sftpdir_nonblock.c,v 1.7 2007/06/08 13:33:08 jehousley Exp $
*
* Sample doing an SFTP directory listing.
*
@ -127,7 +127,7 @@ int main(int argc, char *argv[])
if (auth_pw) {
/* We could authenticate via password */
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2CHANNEL_EAGAIN);
while ((rc = libssh2_userauth_password(session, username, password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "Authentication by password failed.\n");
goto shutdown;
@ -137,7 +137,7 @@ int main(int argc, char *argv[])
while ((rc = libssh2_userauth_publickey_fromfile(session, username,
"/home/username/.ssh/id_rsa.pub",
"/home/username/.ssh/id_rsa",
password)) == LIBSSH2CHANNEL_EAGAIN);
password)) == LIBSSH2_ERROR_EAGAIN);
if (rc) {
fprintf(stderr, "\tAuthentication by public key failed\n");
goto shutdown;
@ -171,7 +171,7 @@ int main(int argc, char *argv[])
LIBSSH2_SFTP_ATTRIBUTES attrs;
/* loop until we fail */
while ((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem), &attrs)) == LIBSSH2SFTP_EAGAIN) {
while ((rc = libssh2_sftp_readdir(sftp_handle, mem, sizeof(mem), &attrs)) == LIBSSH2_ERROR_EAGAIN) {
;
}
if(rc > 0) {
@ -204,7 +204,7 @@ int main(int argc, char *argv[])
printf("%s\n", mem);
}
else if (rc == LIBSSH2SFTP_EAGAIN) {
else if (rc == LIBSSH2_ERROR_EAGAIN) {
/* blocking */
fprintf(stderr, "Blocking\n");
} else {