libuv/docs/code/uvcat/main.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <uv.h>
6 
7 void on_read(uv_fs_t *req);
8 
12 
13 static char buffer[1024];
14 
15 static uv_buf_t iov;
16 
18  if (req->result < 0) {
19  fprintf(stderr, "Write error: %s\n", uv_strerror((int)req->result));
20  }
21  else {
23  }
24 }
25 
27  if (req->result < 0) {
28  fprintf(stderr, "Read error: %s\n", uv_strerror(req->result));
29  }
30  else if (req->result == 0) {
32  // synchronous
34  }
35  else if (req->result > 0) {
36  iov.len = req->result;
38  }
39 }
40 
42  // The request passed to the callback is the same as the one the call setup
43  // function was passed.
44  assert(req == &open_req);
45  if (req->result >= 0) {
46  iov = uv_buf_init(buffer, sizeof(buffer));
48  &iov, 1, -1, on_read);
49  }
50  else {
51  fprintf(stderr, "error opening file: %s\n", uv_strerror((int)req->result));
52  }
53 }
54 
55 int main(int argc, char **argv) {
56  uv_fs_open(uv_default_loop(), &open_req, argv[1], O_RDONLY, 0, on_open);
58 
62  return 0;
63 }
main
int main(int argc, char **argv)
Definition: libuv/docs/code/uvcat/main.c:55
uv_fs_open
UV_EXTERN int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
Definition: unix/fs.c:1812
read_req
uv_fs_t read_req
Definition: libuv/docs/code/uvcat/main.c:10
buffer
static char buffer[1024]
Definition: libuv/docs/code/uvcat/main.c:13
uv_strerror
const UV_EXTERN char * uv_strerror(int err)
Definition: uv-common.c:212
write_req
Definition: benchmark-tcp-write-batch.c:31
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
write_req
uv_fs_t write_req
Definition: libuv/docs/code/uvcat/main.c:11
uv_fs_s::result
ssize_t result
Definition: uv.h:1299
uv_fs_s
Definition: uv.h:1294
python_utils.port_server.stderr
stderr
Definition: port_server.py:51
iov
static uv_buf_t iov
Definition: libuv/docs/code/uvcat/main.c:15
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
on_open
void on_open(uv_fs_t *req)
Definition: libuv/docs/code/uvcat/main.c:41
req
static uv_connect_t req
Definition: test-connection-fail.c:30
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
close_req
static uv_fs_t close_req
Definition: test-fs.c:108
on_read
void on_read(uv_fs_t *req)
Definition: libuv/docs/code/uvcat/main.c:26
on_write
void on_write(uv_fs_t *req)
Definition: libuv/docs/code/uvcat/main.c:17
uv_fs_close
UV_EXTERN int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
Definition: unix/fs.c:1651
uv_fs_read
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1826
uv.h
uv_buf_t
Definition: unix.h:121
uv_fs_write
UV_EXTERN int uv_fs_write(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
Definition: unix/fs.c:1995
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
uv_buf_t::len
size_t len
Definition: unix.h:123
uv_fs_req_cleanup
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t *req)
Definition: unix/fs.c:2024
open_req
uv_fs_t open_req
Definition: libuv/docs/code/uvcat/main.c:9


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:17