node-unix-socket
Version:
node-unix-socket allows you to use SO_REUSEPORT, SOCK_SEQPACKET, SOCK_DGRAM in Node.js.
78 lines (77 loc) • 2.11 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { EventEmitter } from 'events';
export declare type SendCb = (err: undefined | Error) => void;
/**
* DgramSocket is used to create a SOCK_DGRAM unix domain socket.
* Currently DgramSocket doesn't work with `cluster` module.
*
* DgramSocket is also an `EventEmitter` and will emit events including:
*
* ### Event: `'data'`
* - buffer `Buffer`
* - path `string`
*
* Emitted when data is received. `path` indicates remote address information.
*
* ### Event: `'error'`
* - error `Error`
*
* Emitted when an error occurs.
*
* ### Event: `'close'`
* The 'close' event is emitted after a socket is closed with close().
*/
export declare class DgramSocket extends EventEmitter {
private closed;
private wrap;
constructor();
private onData;
private onError;
private checkClosed;
/**
* Listen for datagram messages on a path.
* @param socketPath
*/
bind(socketPath: string): void;
/**
* Send messages to the destination path.
* @param buf
* @param offset
* @param length
* @param destPath
* @param onWrite
*/
sendTo(buf: Buffer, offset: number, length: number, destPath: string, onWrite?: SendCb): void;
/**
* @returns the SO_RCVBUF socket receive buffer size in bytes.
*/
getRecvBufferSize(): number;
/**
* Sets the SO_RCVBUF socket option. Sets the maximum socket receive buffer in bytes.
* @param size
* @returns
*/
setRecvBufferSize(size: number): void;
/**
* @returns the SO_SNDBUF socket send buffer size in bytes.
*/
getSendBufferSize(): number;
/**
* Sets the SO_SNDBUF socket option. Sets the maximum socket send buffer in bytes.
* @param size
* @returns
*/
setSendBufferSize(size: number): void;
/**
* Returns the bound address.
* @returns
*/
address(): string;
/**
* Close the underlying socket and stop listening for data on it.
* @returns
*/
close(): void;
}