grpc
third_party
libuv
docs
code
progress
libuv/docs/code/progress/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
}
print_progress
void print_progress(uv_async_t *handle)
Definition:
libuv/docs/code/progress/main.c:31
status
absl::Status status
Definition:
rls.cc:251
fake_download
void fake_download(uv_work_t *req)
Definition:
libuv/docs/code/progress/main.c:12
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition:
unix/core.c:361
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
python_utils.port_server.stderr
stderr
Definition:
port_server.py:51
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition:
unix/core.c:112
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition:
uv-common.c:733
uv_async_s
Definition:
uv.h:834
req
static uv_connect_t req
Definition:
test-connection-fail.c:30
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition:
uv.h:254
after
void after(uv_work_t *req, int status)
Definition:
libuv/docs/code/progress/main.c:26
uv.h
uv_async_init
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
Definition:
unix/async.c:44
async
uv_async_t async
Definition:
libuv/docs/code/progress/main.c:8
percentage
double percentage
Definition:
libuv/docs/code/progress/main.c:10
main
int main()
Definition:
libuv/docs/code/progress/main.c:36
loop
uv_loop_t * loop
Definition:
libuv/docs/code/progress/main.c:7
handle
static csh handle
Definition:
test_arm_regression.c:16
uv_handle_s
Definition:
uv.h:441
uv_loop_s
Definition:
uv.h:1767
size
voidpf void uLong size
Definition:
bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv_work_s
Definition:
uv.h:1055
uv_async_send
UV_EXTERN int uv_async_send(uv_async_t *async)
Definition:
unix/async.c:62
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:17