diff --git a/easystorage.c b/easystorage.c index 706582e..b32eef4 100644 --- a/easystorage.c +++ b/easystorage.c @@ -124,14 +124,15 @@ static void on_progress(int ret, const char *msg, size_t len, void *userData) { // Manages deallocation of resp such that it only gets deallocated after both // this call returns AND the callback has run. Will leak memory if the call // succeeds but the callback then fails to run. -static int call_wait(int dispatch_ret, resp *r, char **out) { +#define call_wait(dispatch_ret, r, out) call_wait_impl(__func__, __LINE__, dispatch_ret, r, out) +static int call_wait_impl(const char *caller_name, int caller_line, int dispatch_ret, resp *r, char **out) { if (dispatch_ret != RET_OK) { resp_destroy(r); return RET_ERR; } if (resp_wait(r)) { - fprintf(stderr, "CRITICAL: Call timed out!"); + fprintf(stderr, "CRITICAL: Call timed out at %s, line %d\n", caller_name, caller_line); } pthread_mutex_lock(&mutex); @@ -218,6 +219,13 @@ int e_storage_stop(STORAGE_NODE node) { return call_wait(storage_stop(node, (StorageCallback) on_complete, r), r, NULL); } +int e_storage_close(STORAGE_NODE node) { + if (!node) + return RET_ERR; + resp *r = resp_alloc(); + return call_wait(storage_close(node, (StorageCallback) on_complete, r), r, NULL); +} + int e_storage_destroy(STORAGE_NODE node) { if (!node) return RET_ERR; @@ -302,7 +310,8 @@ int e_storage_download(STORAGE_NODE node, const char *cid, const char *filepath, } int e_storage_delete(STORAGE_NODE node, const char *cid) { - if (!node || !cid) return RET_ERR; + if (!node || !cid) + return RET_ERR; resp *r = resp_alloc(); int ret = call_wait(storage_delete(node, cid, on_complete, r), r, NULL); diff --git a/easystorage.h b/easystorage.h index 3bf5ce0..d952a54 100644 --- a/easystorage.h +++ b/easystorage.h @@ -25,6 +25,7 @@ STORAGE_NODE e_storage_new(node_config config); int e_storage_start(STORAGE_NODE node); int e_storage_stop(STORAGE_NODE node); +int e_storage_close(STORAGE_NODE node); int e_storage_destroy(STORAGE_NODE node); // Retrieves the node's SPR (caller must free), or NULL on failure. diff --git a/examples/downloader.c b/examples/downloader.c index 6701b95..79482c0 100644 --- a/examples/downloader.c +++ b/examples/downloader.c @@ -37,5 +37,6 @@ int main(int argc, char *argv[]) { if (e_storage_start(node) != RET_OK) panic("Failed to start storage node"); if (e_storage_download(node, cid, filepath, progress) != RET_OK) panic("Failed to download file"); e_storage_stop(node); + e_storage_close(node); e_storage_destroy(node); } diff --git a/examples/uploader.c b/examples/uploader.c index a41be62..883cef9 100644 --- a/examples/uploader.c +++ b/examples/uploader.c @@ -52,6 +52,7 @@ int main(int argc, char *argv[]) { free(cid); free(spr); e_storage_stop(node); + e_storage_close(node); e_storage_destroy(node); return 0;