Static methods

@:noExprstaticaccept<T>(server:TStream<T>, client:TStream<T>):Result<NoData>

This call is used in conjunction with Stream.listen() to accept incoming connections. Call this function after receiving a callback of listen(callback) to accept the connection. Before calling this function the client handle must be initialized.

When the callback of listen(callback) is called it is guaranteed that this function will complete successfully the first time.

client should be a freshly-initialized stream.

@:noExprstaticisReadable(stream:Stream):Bool

Indicates whether the stream is readable (has data).

@:noExprstaticisWritable(stream:Stream):Bool

Indicates whether the stream is writable (has space in buffers).

@:noExprstaticlisten(stream:Stream, callback:(result:Result<NoData>) ‑> Void, ?backlog:Int):Void

Starts listening for incoming connections.

backlog indicates the number of connections the kernel might queue. When a new incoming connection is received the callback is called.

@:noExprstaticreadStart(stream:Stream, callback:(result:Result<Buffer>) ‑> Void, ?allocate:(size:Int) ‑> Buffer):Void

Calls the callback whenever data is available on the stream.

The amount of data read is equal to the length of the buffer passed to the callback. allocate is called immediately before each call to the main callback, to create buffer, into which the data will be read.

The end of the stream (typically, when the remote peer closes or shuts down the connection) is indicated by UVError.UV_EOF being passed to the callback. Note that this behavior is different from eval.luv.File.read.

Zero-length reads are possible, and do not indicate the end of stream. Instead, they usually indicate UVError.UV_EAGAIN inside libuv; libuv still calls the callback in order to give the C user a chance to deallocate the data buffer. This is not usually an issue in OCaml (which is the backend for eval target of Haxe), so a wrapper of this function can usually simply ignore zero-length reads. It is then also safe to convert UVError.UV_EOF to zero-length reads in a higher-level API, for consistency with reading files, and in accordance with OS API convention.

To read only once, call eval.luv.Stream.readStop immediately, in the callback. Otherwise, the main callback will be called repeatedly.

@:noExprstaticreadStop(stream:Stream):Result<NoData>

Stops reading.

@:noExprstaticsetBlocking(stream:Stream, block:Bool):Result<NoData>

Sets the blocking mode of the stream.

@:noExprstaticshutdown(stream:Stream, callback:(result:Result<NoData>) ‑> Void):Void

Shuts down the write side of the stream.

@:noExprstatictryWrite(stream:Stream, data:Array<Buffer>):Result<Int>

Same as eval.luv.Stream.write(), but won’t queue a write request if it can’t be completed immediately.

Returns the number of bytes written.

@:noExprstaticwrite(stream:Stream, data:Array<Buffer>, callback:(result:Result<NoData>, bytesWritten:Int) ‑> Void):Result<NoData>

Writes the given buffer to the stream.

The second argument passed to the callback is the number of bytes written. libuv has an internal queue of writes, in part to implement retry. This means that writes can be partial at the libuv API level, so it is possible to receive both an UVError result, and for some data to have been successfully written.

@:noExprstaticwrite2(stream:TStream<Pipe>, data:Array<Buffer>, sendHandle:SendHandle, callback:(result:Result<NoData>, bytesWritten:Int) ‑> Void):Result<NoData>

Like eval.luv.Stream.write, but allows sending a TCP socket or pipe over the stream.