1 | #ifndef NVIM_EVENT_STREAM_H |
2 | #define NVIM_EVENT_STREAM_H |
3 | |
4 | #include <stdbool.h> |
5 | #include <stddef.h> |
6 | |
7 | #include <uv.h> |
8 | |
9 | #include "nvim/event/loop.h" |
10 | #include "nvim/rbuffer.h" |
11 | |
12 | typedef struct stream Stream; |
13 | /// Type of function called when the Stream buffer is filled with data |
14 | /// |
15 | /// @param stream The Stream instance |
16 | /// @param buf The associated RBuffer instance |
17 | /// @param count Number of bytes that was read. |
18 | /// @param data User-defined data |
19 | /// @param eof If the stream reached EOF. |
20 | typedef void (*stream_read_cb)(Stream *stream, RBuffer *buf, size_t count, |
21 | void *data, bool eof); |
22 | |
23 | /// Type of function called when the Stream has information about a write |
24 | /// request. |
25 | /// |
26 | /// @param stream The Stream instance |
27 | /// @param data User-defined data |
28 | /// @param status 0 on success, anything else indicates failure |
29 | typedef void (*stream_write_cb)(Stream *stream, void *data, int status); |
30 | typedef void (*stream_close_cb)(Stream *stream, void *data); |
31 | |
32 | struct stream { |
33 | bool closed; |
34 | bool did_eof; |
35 | union { |
36 | uv_pipe_t pipe; |
37 | uv_tcp_t tcp; |
38 | uv_idle_t idle; |
39 | #ifdef WIN32 |
40 | uv_tty_t tty; |
41 | #endif |
42 | } uv; |
43 | uv_stream_t *uvstream; |
44 | uv_buf_t uvbuf; |
45 | RBuffer *buffer; |
46 | uv_file fd; |
47 | stream_read_cb read_cb; |
48 | stream_write_cb write_cb; |
49 | void *cb_data; |
50 | stream_close_cb close_cb, internal_close_cb; |
51 | void *close_cb_data, *internal_data; |
52 | size_t fpos; |
53 | size_t curmem; |
54 | size_t maxmem; |
55 | size_t pending_reqs; |
56 | size_t num_bytes; |
57 | MultiQueue *events; |
58 | }; |
59 | |
60 | #ifdef INCLUDE_GENERATED_DECLARATIONS |
61 | # include "event/stream.h.generated.h" |
62 | #endif |
63 | #endif // NVIM_EVENT_STREAM_H |
64 | |