mirror of
https://github.com/logos-storage/easylibstorage.git
synced 2026-02-10 03:33:07 +00:00
feat: add storage node close; improve timeout message
This commit is contained in:
parent
36b0242444
commit
607fb8d5f8
@ -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);
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user