Open creationix opened 8 years ago
You can see the general libuv shape in the luv docs and libuv's docs
Create a new uv_tcp_t
instance. This will inherit from uv.Tcp.prototype
which inherits from uv.Stream.prototype
which inherits from uv.Handle.prototype
.
If flags
is not set, uv_tcp_init
is used, if it is set, uv_tcp_init_ex
is used passing the flags through.
Below when tcp.*
is used, it means uv.Tcp.prototype
which become methods on the tcp
instance.
Open an existing file descriptor or SOCKET as a TCP handle.
The file descriptor is set to non-blocking mode.
Enable / disable Nagle’s algorithm.
Enable / disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.
This setting is used to tune a TCP server for the desired performance. Having simultaneous accepts can significantly improve the rate of accepting connections (which is why it is enabled by default) but may lead to uneven load distribution in multi-process setups.
...
Start of docs is at https://github.com/creationix/nucleus/blob/master/api/uv.md
This task is to design the interface that wraps libuv and exposes it to JavaScript. This should be as minimal as possible while still feeling like natural JavaScript and not C.
For example, in libuv, there is a hierarchy of structs that act like classes with inheritance. In JS, we can use prototype chains for the
uv_tcp_t
methods that inherits fromuv_stream_t
methods that inherits fromuv_handle_t
methods.All libuv functions are plain C functions. There are no classes. The ones that act like methods accept the struct as the first argument. In luv, I exposed these in both ways.
For example, here is a sample TCP echo server in plain luv.
In lua, there are no methods per-se, but the
obj:name(...)
syntax means to callobj.name(obj, ...)
injecting the thing to the left of the colon as the first argument. In JS, we havethis
which can be used in a similar way.