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

Data Structures

struct  WRequest
 

Macros

#define DEFAULT_MAXMEM   1024 * 1024 * 2000
 

Functions

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
 

Variables

void stream cb_data = data
 

Macro Definition Documentation

#define DEFAULT_MAXMEM   1024 * 1024 * 2000

Function Documentation

void wstream_init ( Stream stream,
size_t  maxmem 
)
void wstream_init_fd ( Loop loop,
Stream stream,
int  fd,
size_t  maxmem 
)
void wstream_init_stream ( Stream stream,
uv_stream_t *  uvstream,
size_t  maxmem 
)
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)

Parameters
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).
Returns
The allocated WBuffer instance
void wstream_release_wbuffer ( WBuffer buffer)
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.

Note
This callback will not fire if the write request couldn't even be queued properly (i.e.: when wstream_write() returns an error).
Parameters
streamThe Stream instance
cbThe callback
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.

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

Variable Documentation

void stream cb_data = data