move loop polling for upload completion into separate function

This commit is contained in:
josch
2014-12-29 13:57:53 +01:00
parent 07e545bd87
commit 80036b5bd9
8 changed files with 54 additions and 63 deletions

View File

@@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "../utils/strings.h"
#include "apicalls.h"
@@ -402,3 +403,29 @@ int mfconn_get_max_num_retries(mfconn * conn)
{
return conn->max_num_retries;
}
int mfconn_upload_poll_for_completion(mfconn * conn, const char *upload_key)
{
int status;
int fileerror;
int retval;
for (;;) {
// no need to update the secret key after this
retval = mfconn_api_upload_poll_upload(conn, upload_key, &status,
&fileerror);
if (retval != 0) {
fprintf(stderr, "mfconn_api_upload_poll_upload failed\n");
return -1;
}
fprintf(stderr, "status: %d, filerror: %d\n", status, fileerror);
// values 98 and 99 are terminal states for a completed upload
if (status == 99 || status == 98) {
fprintf(stderr, "done\n");
break;
}
sleep(1);
}
return 0;
}