Data Structures | Macros | Functions | Variables
wstream.c File Reference
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/wstream.h"
#include "nvim/log.h"
#include "nvim/memory.h"
#include "nvim/vim.h"

Data Structures

struct  WRequest


#define DEFAULT_MAXMEM   1024 * 1024 * 2000


void wstream_init_fd (Loop *loop, Stream *stream, int fd, size_t maxmem) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(2)
void wstream_init_stream (Stream *stream, uv_stream_t *uvstream, size_t maxmem) FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(2)
void wstream_init (Stream *stream, size_t maxmem)
void wstream_set_write_cb (Stream *stream, stream_write_cb cb, void *data) FUNC_ATTR_NONNULL_ARG(1
bool wstream_write (Stream *stream, WBuffer *buffer) FUNC_ATTR_NONNULL_ALL
WBufferwstream_new_buffer (char *data, size_t size, size_t refcount, wbuffer_data_finalizer cb) FUNC_ATTR_NONNULL_ARG(1)
void wstream_release_wbuffer (WBuffer *buffer) FUNC_ATTR_NONNULL_ALL


void stream cb_data = data

Macro Definition Documentation


#define DEFAULT_MAXMEM   1024 * 1024 * 2000

Function Documentation

◆ wstream_init()

void wstream_init ( Stream stream,
size_t  maxmem 

◆ wstream_init_fd()

void wstream_init_fd ( Loop loop,
Stream stream,
int  fd,
size_t  maxmem 

◆ wstream_init_stream()

void wstream_init_stream ( Stream stream,
uv_stream_t *  uvstream,
size_t  maxmem 

◆ wstream_new_buffer()

WBuffer* wstream_new_buffer ( char *  data,
size_t  size,
size_t  refcount,
wbuffer_data_finalizer  cb 

Creates a WBuffer object for holding output data. Instances of this object can be reused across Stream instances, and the memory is freed automatically when no longer needed(it tracks the number of references internally)

dataData stored by the WBuffer
sizeThe size of the data array
refcountThe number of references for the WBuffer. This will be used by Stream instances to decide when a WBuffer should be freed.
cbPointer to function that will be responsible for freeing the buffer data(passing 'free' will work as expected).
The allocated WBuffer instance

◆ wstream_release_wbuffer()

void wstream_release_wbuffer ( WBuffer buffer)

◆ wstream_set_write_cb()

void wstream_set_write_cb ( Stream stream,
stream_write_cb  cb,
void data 

Sets a callback that will be called on completion of a write request, indicating failure/success.

This affects all requests currently in-flight as well. Overwrites any possible earlier callback.

This callback will not fire if the write request couldn't even be queued properly (i.e.: when wstream_write() returns an error).
streamThe Stream instance
cbThe callback

◆ wstream_write()

bool wstream_write ( Stream stream,
WBuffer buffer 

Queues data for writing to the backing file descriptor of a Stream instance. This will fail if the write would cause the Stream use more memory than specified by maxmem.

streamThe Stream instance
bufferThe buffer which contains data to be written
false if the write failed

Variable Documentation

◆ cb_data

void stream cb_data = data