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
7
uv_loop_t
*
loop
;
8
uv_async_t
async
;
9
10
double
percentage
;
11
12
void
fake_download
(
uv_work_t
*
req
) {
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
;
18
uv_async_send
(&
async
);
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"
);
28
uv_close
((
uv_handle_t
*) &
async
,
NULL
);
29
}
30
31
void
print_progress
(
uv_async_t
*
handle
) {
32
double
percentage
= *((
double
*)
handle
->data);
33
fprintf(stderr,
"Downloaded %.2f%%\n"
,
percentage
);
34
}
35
36
int
main
() {
37
loop
=
uv_default_loop
();
38
39
uv_work_t
req
;
40
int
size
= 10240;
41
req
.data = (
void
*) &
size
;
42
43
uv_async_init
(
loop
, &
async
,
print_progress
);
44
uv_queue_work
(
loop
, &
req
,
fake_download
,
after
);
45
46
return
uv_run
(
loop
,
UV_RUN_DEFAULT
);
47
}
handle
static mcore_handle handle
Definition:
asm_mcore.c:8
NULL
#define NULL
Definition:
cris-opc.c:27
req
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
size
voidpf void uLong size
Definition:
ioapi.h:138
main
int main(int argc, const char **argv)
Definition:
main.c:340
status
static const char struct stat static buf struct stat static buf static vhangup int status
Definition:
sflib.h:145
uv_async_s
Definition:
uv.h:844
uv_handle_s
Definition:
uv.h:444
uv_loop_s
Definition:
uv.h:1780
uv_work_s
Definition:
uv.h:1066
loop
uv_loop_t * loop
Definition:
main.c:7
after
void after(uv_work_t *req, int status)
Definition:
main.c:26
async
uv_async_t async
Definition:
main.c:8
print_progress
void print_progress(uv_async_t *handle)
Definition:
main.c:31
percentage
double percentage
Definition:
main.c:10
fake_download
void fake_download(uv_work_t *req)
Definition:
main.c:12
uv.h
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:255
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
core.c:365
uv_queue_work
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_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition:
core.c:108
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:763
uv_async_init
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
Definition:
async.c:45
uv_async_send
UV_EXTERN int uv_async_send(uv_async_t *async)
Definition:
async.c:63
subprojects
libuv-v1.40.0
docs
code
progress
main.c
Generated by
1.9.1