aboutsummaryrefslogtreecommitdiff
path: root/src/os/wstream.h
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-04-17 16:11:23 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-18 16:12:00 -0300
commit913e92324adafe77eeeeefb42033fa06053ffe4c (patch)
treee741ed7ef6f09ea5f0d3425504201807d5f1a1cf /src/os/wstream.h
parentd31d3dda3dd1f7a18cca4c99a33cee26c62e57af (diff)
downloadrneovim-913e92324adafe77eeeeefb42033fa06053ffe4c.tar.gz
rneovim-913e92324adafe77eeeeefb42033fa06053ffe4c.tar.bz2
rneovim-913e92324adafe77eeeeefb42033fa06053ffe4c.zip
Extract writing boilerplate into wstream.c module
Diffstat (limited to 'src/os/wstream.h')
-rw-r--r--src/os/wstream.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/os/wstream.h b/src/os/wstream.h
new file mode 100644
index 0000000000..4a557ffd9f
--- /dev/null
+++ b/src/os/wstream.h
@@ -0,0 +1,40 @@
+#ifndef NEOVIM_OS_WSTREAM_H
+#define NEOVIM_OS_WSTREAM_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <uv.h>
+
+#include "os/wstream_defs.h"
+
+/// Creates a new WStream instance. A WStream encapsulates all the boilerplate
+/// necessary for writing to a libuv stream.
+///
+/// @param maxmem Maximum amount memory used by this `WStream` instance.
+/// @return The newly-allocated `WStream` instance
+WStream * wstream_new(uint32_t maxmem);
+
+/// Frees all memory allocated for a WStream instance
+///
+/// @param wstream The `WStream` instance
+void wstream_free(WStream *wstream);
+
+/// Sets the underlying `uv_stream_t` instance
+///
+/// @param wstream The `WStream` instance
+/// @param stream The new `uv_stream_t` instance
+void wstream_set_stream(WStream *wstream, uv_stream_t *stream);
+
+/// Queues data for writing to the backing file descriptor of a `WStream`
+/// instance. This will fail if the write would cause the WStream use more
+/// memory than specified by `maxmem`.
+///
+/// @param wstream The `WStream` instance
+/// @param buffer The buffer which contains data to be written
+/// @param length Number of bytes that should be written from `buffer`
+/// @param free If true, `buffer` will be freed after the write is complete
+/// @return true if the data was successfully queued, false otherwise.
+bool wstream_write(WStream *wstream, char *buffer, uint32_t length, bool free);
+
+#endif // NEOVIM_OS_WSTREAM_H
+