Rizin
unix-like reverse engineering framework and cli tools
main.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 
5 #include <uv.h>
6 
9 
10 double percentage;
11 
13  int size = *((int*) req->data);
14  int downloaded = 0;
15  while (downloaded < size) {
16  percentage = downloaded*100.0/size;
17  async.data = (void*) &percentage;
19 
20  sleep(1);
21  downloaded += (200+random())%1000; // can only download max 1000bytes/sec,
22  // but at least a 200;
23  }
24 }
25 
26 void after(uv_work_t *req, int status) {
27  fprintf(stderr, "Download complete\n");
29 }
30 
32  double percentage = *((double*) handle->data);
33  fprintf(stderr, "Downloaded %.2f%%\n", percentage);
34 }
35 
36 int main() {
38 
39  uv_work_t req;
40  int size = 10240;
41  req.data = (void*) &size;
42 
45 
46  return uv_run(loop, UV_RUN_DEFAULT);
47 }
static mcore_handle handle
Definition: asm_mcore.c:8
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
voidpf void uLong size
Definition: ioapi.h:138
int main(int argc, const char **argv)
Definition: main.c:340
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
Definition: uv.h:844
Definition: uv.h:1780
Definition: uv.h:1066
uv_loop_t * loop
Definition: main.c:7
void after(uv_work_t *req, int status)
Definition: main.c:26
uv_async_t async
Definition: main.c:8
void print_progress(uv_async_t *handle)
Definition: main.c:31
double percentage
Definition: main.c:10
void fake_download(uv_work_t *req)
Definition: main.c:12
@ UV_RUN_DEFAULT
Definition: uv.h:255
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: core.c:365
UV_EXTERN int uv_queue_work(uv_loop_t *loop, uv_work_t *req, uv_work_cb work_cb, uv_after_work_cb after_work_cb)
Definition: threadpool.c:338
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
Definition: async.c:45
UV_EXTERN int uv_async_send(uv_async_t *async)
Definition: async.c:63