diff options
| author | Mistivia <i@mistivia.com> | 2025-09-13 20:53:56 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-09-13 20:53:56 +0800 |
| commit | a4daf467f871b0e77f07f1071b47b960da7bfba9 (patch) | |
| tree | 43b8847b395a90f5aadb57593c0d84e2c13cca7c /s3_worker.c | |
| parent | f3eeea1d7092f3ca98836035bf75b941d14c2067 (diff) | |
add s3 client
Diffstat (limited to 's3_worker.c')
| -rw-r--r-- | s3_worker.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/s3_worker.c b/s3_worker.c new file mode 100644 index 0000000..5f21155 --- /dev/null +++ b/s3_worker.c @@ -0,0 +1,72 @@ +#include "s3_worker.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "task_queue.h" + +TaskQueue task_queue; + +void exec_s3_task(void *vtask) { + char obj_name_buf[256]; + S3Task *task = vtask; + if (task->task_type == kUploadTask) { + // TODO + } else if (task->task_type == kDeleteTask) { + // TODO + } else if (task->task_type == kClearTask) { + // TODO + } else { + fprintf(stderr, "unknown task type.\n"); + } + free(task->local_file); + free(task->remote_name); + free(task); +} + +void s3_worker_init() { + s3client_init(); + TaskQueue_init(&task_queue, 128); +} + +void s3_worker_push(S3Task task) { + S3Task *ptask = malloc(sizeof(S3Task)); + *ptask = task; + ptask->local_file = ptask->local_file; + ptask->remote_name = ptask->remote_name; + TaskQueue_push(&task_queue, exec_s3_task, ptask); +} + +void* s3_worker_main(void *ctx) { + while (1) { + TaskFn task_fn; + void *arg; + TaskQueue_pop(&task_queue, &task_fn, &arg); + (*task_fn)(arg); + } +} + +S3Task s3_upload_task(const char *local, const char *remote) { + return (S3Task) { + .task_type = kUploadTask, + .local_file = strdup(local), + .remote_name = strdup(remote), + }; +} + +S3Task s3_delete_task(const char *name) { + return (S3Task) { + .task_type = kDeleteTask, + .local_file = NULL, + .remote_name = strdup(name), + }; +} + +S3Task s3_clear_task() { + return (S3Task) { + .task_type = kClearTask, + .local_file = NULL, + .remote_name = NULL, + }; +}
\ No newline at end of file |
