forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
173
Kha/Backends/Node/js/node/net/Server.hx
Normal file
173
Kha/Backends/Node/js/node/net/Server.hx
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (C)2014-2020 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package js.node.net;
|
||||
|
||||
import haxe.extern.EitherType;
|
||||
import js.node.events.EventEmitter;
|
||||
import js.node.net.Socket.SocketAdress;
|
||||
#if haxe4
|
||||
import js.lib.Error;
|
||||
#else
|
||||
import js.Error;
|
||||
#end
|
||||
|
||||
/**
|
||||
Enumeration of events emitted by the `Server` objects
|
||||
**/
|
||||
@:enum abstract ServerEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> {
|
||||
/**
|
||||
Emitted when the server has been bound after calling `Server.listen`.
|
||||
**/
|
||||
var Listening:ServerEvent<Void->Void> = "listening";
|
||||
|
||||
/**
|
||||
Emitted when a new connection is made.
|
||||
**/
|
||||
var Connection:ServerEvent<Socket->Void> = "connection";
|
||||
|
||||
/**
|
||||
Emitted when the server closes.
|
||||
Note that if connections exist, this event is not emitted until all connections are ended.
|
||||
**/
|
||||
var Close:ServerEvent<Void->Void> = "close";
|
||||
|
||||
/**
|
||||
Emitted when an error occurs.
|
||||
The 'close' event will be called directly following this event. See example in discussion of server.listen.
|
||||
**/
|
||||
var Error:ServerEvent<Error->Void> = "error";
|
||||
}
|
||||
|
||||
private typedef ServerListenOptionsBase = {
|
||||
@:optional var exclusive:Bool;
|
||||
}
|
||||
|
||||
/**
|
||||
Options for the `Server.listen` method (TCP version).
|
||||
**/
|
||||
typedef ServerListenOptionsTcp = {
|
||||
> ServerListenOptionsBase,
|
||||
@:optional var port:Int;
|
||||
@:optional var host:String;
|
||||
@:optional var backlog:Int;
|
||||
}
|
||||
|
||||
/**
|
||||
Options for the `Server.listen` method (UNIX version).
|
||||
**/
|
||||
typedef ServerListenOptionsUnix = {
|
||||
> ServerListenOptionsBase,
|
||||
@:optional var path:String;
|
||||
}
|
||||
|
||||
/**
|
||||
This class is used to create a TCP or local server.
|
||||
**/
|
||||
@:jsRequire("net", "Server")
|
||||
extern class Server extends EventEmitter<Server> {
|
||||
/**
|
||||
Begin accepting connections on the specified `port` and `hostname`.
|
||||
|
||||
If the `hostname` is omitted, the server will accept connections on any IPv6 address (::) when IPv6 is available,
|
||||
or any IPv4 address (0.0.0.0) otherwise.
|
||||
A `port` value of zero will assign a random port.
|
||||
|
||||
`backlog` is the maximum length of the queue of pending connections. The actual length will be determined
|
||||
by your OS through sysctl settings such as tcp_max_syn_backlog and somaxconn on linux.
|
||||
The default value of this parameter is 511 (not 512).
|
||||
|
||||
When `path` is provided, start a local socket server listening for connections on the given path.
|
||||
|
||||
When `handle` is provided, it should be either a server or socket (anything with an underlying `_handle` member),
|
||||
or a {fd: <n>} object. This will cause the server to accept connections on the specified handle,
|
||||
but it is presumed that the file descriptor or handle has already been bound to a port or domain socket.
|
||||
Listening on a file descriptor is not supported on Windows.
|
||||
|
||||
This function is asynchronous. When the server has been bound, 'listening' event will be emitted.
|
||||
The last parameter `callback` will be added as an listener for the 'listening' event.
|
||||
**/
|
||||
@:overload(function(path:String, ?callback:Void->Void):Void {})
|
||||
@:overload(function(handle:EitherType<Dynamic, {fd:Int}>, ?callback:Void->Void):Void {})
|
||||
@:overload(function(port:Int, ?callback:Void->Void):Void {})
|
||||
@:overload(function(port:Int, backlog:Int, ?callback:Void->Void):Void {})
|
||||
@:overload(function(port:Int, hostname:String, ?callback:Void->Void):Void {})
|
||||
@:overload(function(port:Int, hostname:String, backlog:Int, ?callback:Void->Void):Void {})
|
||||
function listen(options:EitherType<ServerListenOptionsTcp, ServerListenOptionsUnix>, ?callback:Void->Void):Void;
|
||||
|
||||
/**
|
||||
Stops the server from accepting new connections and keeps existing connections.
|
||||
This function is asynchronous, the server is finally closed when all connections are ended
|
||||
and the server emits a 'close' event.
|
||||
|
||||
The optional callback will be called once the 'close' event occurs. Unlike that event,
|
||||
it will be called with an Error as its only argument if the server was not open when it was closed.
|
||||
**/
|
||||
@:overload(function(callback:Error->Void):Void {})
|
||||
function close(?callback:Void->Void):Void;
|
||||
|
||||
/**
|
||||
Returns the bound address, the address family name and port of the server as reported by the operating system.
|
||||
Useful to find which port was assigned when giving getting an OS-assigned address.
|
||||
**/
|
||||
function address():SocketAdress;
|
||||
|
||||
/**
|
||||
Calling `unref` on a server will allow the program to exit if this is the only active server in the event system.
|
||||
If the server is already `unref`d calling `unref` again will have no effect.
|
||||
**/
|
||||
function unref():Void;
|
||||
|
||||
/**
|
||||
Opposite of `unref`, calling `ref` on a previously `unref`d server
|
||||
will not let the program exit if it's the only server left (the default behavior).
|
||||
|
||||
If the server is `ref`d calling `ref` again will have no effect.
|
||||
**/
|
||||
function ref():Void;
|
||||
|
||||
/**
|
||||
A boolean indicating whether or not the server is listening for connections.
|
||||
**/
|
||||
var listening(default, null):Bool;
|
||||
|
||||
/**
|
||||
Set this property to reject connections when the server's connection count gets high.
|
||||
It is not recommended to use this option once a socket has been sent to a child with child_process.fork().
|
||||
**/
|
||||
var maxConnections:Int;
|
||||
|
||||
/**
|
||||
The number of concurrent connections on the server.
|
||||
|
||||
This becomes null when sending a socket to a child with child_process.fork().
|
||||
To poll forks and get current number of active connections use asynchronous `getConnections` instead.
|
||||
**/
|
||||
@:deprecated("please use `getConnections` instead")
|
||||
var connections(default, null):Null<Int>;
|
||||
|
||||
/**
|
||||
Asynchronously get the number of concurrent connections on the server.
|
||||
Works when sockets were sent to forks.
|
||||
**/
|
||||
function getConnections(callback:Error->Int->Void):Void;
|
||||
}
|
367
Kha/Backends/Node/js/node/net/Socket.hx
Normal file
367
Kha/Backends/Node/js/node/net/Socket.hx
Normal file
@ -0,0 +1,367 @@
|
||||
/*
|
||||
* Copyright (C)2014-2020 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package js.node.net;
|
||||
|
||||
import haxe.extern.EitherType;
|
||||
import js.node.Dns;
|
||||
import js.node.events.EventEmitter.Event;
|
||||
#if haxe4
|
||||
import js.lib.Error;
|
||||
#else
|
||||
import js.Error;
|
||||
#end
|
||||
|
||||
/**
|
||||
Enumeration of events for `Socket` objects.
|
||||
**/
|
||||
@:enum abstract SocketEvent<T:haxe.Constraints.Function>(Event<T>) to Event<T> {
|
||||
/**
|
||||
Emitted after resolving the hostname but before connecting.
|
||||
Not applicable to UNIX sockets.
|
||||
**/
|
||||
var Lookup:SocketEvent<Null<Error>->String->DnsAddressFamily->Void> = "lookup";
|
||||
|
||||
/**
|
||||
Emitted when a socket connection is successfully established. See `Socket.connect`.
|
||||
**/
|
||||
var Connect:SocketEvent<Void->Void> = "connect";
|
||||
|
||||
/**
|
||||
Emitted when data is received.
|
||||
The argument data will be a `Buffer` or `String`.
|
||||
Encoding of data is set by `Socket.setEncoding`.
|
||||
|
||||
Note that the data will be lost if there is no listener when a Socket emits a 'data' event.
|
||||
**/
|
||||
var Data:SocketEvent<EitherType<Buffer, String>->Void> = "data";
|
||||
|
||||
/**
|
||||
Emitted when the other end of the socket sends a FIN packet.
|
||||
|
||||
By default (allowHalfOpen == false) the socket will destroy its file descriptor once
|
||||
it has written out its pending write queue. However, by setting allowHalfOpen == true
|
||||
the socket will not automatically `end` its side allowing the user to write arbitrary amounts of data,
|
||||
with the caveat that the user is required to `end` their side now.
|
||||
**/
|
||||
var End:SocketEvent<Void->Void> = "end";
|
||||
|
||||
/**
|
||||
Emitted if the socket times out from inactivity.
|
||||
This is only to notify that the socket has been idle
|
||||
The user must manually close the connection.
|
||||
See also: `Socket.setTimeout`
|
||||
**/
|
||||
var Timeout:SocketEvent<Void->Void> = "timeout";
|
||||
|
||||
/**
|
||||
Emitted when the write buffer becomes empty. Can be used to throttle uploads.
|
||||
See also: the return values of `Socket.write`
|
||||
**/
|
||||
var Drain:SocketEvent<Void->Void> = "drain";
|
||||
|
||||
/**
|
||||
Emitted when an error occurs. The 'close' event will be called directly following this event.
|
||||
**/
|
||||
var Error:SocketEvent<Error->Void> = "error";
|
||||
|
||||
/**
|
||||
Emitted once the socket is fully closed.
|
||||
The argument `had_error` is a boolean which says if the socket was closed due to a transmission error.
|
||||
|
||||
Listener arguments:
|
||||
had_error - true if the socket had a transmission error
|
||||
**/
|
||||
var Close:SocketEvent<Bool->Void> = "close";
|
||||
}
|
||||
|
||||
typedef SocketOptionsBase = {
|
||||
/**
|
||||
If true, then the socket won't automatically send a FIN packet
|
||||
when the other end of the socket sends a FIN packet.
|
||||
|
||||
The socket becomes non-readable, but still writable. You should call the `end` method explicitly.
|
||||
See `end` event for more information.
|
||||
|
||||
Default: false
|
||||
**/
|
||||
@:optional var allowHalfOpen:Bool;
|
||||
}
|
||||
|
||||
/**
|
||||
Options for creating new `Socket` object.
|
||||
**/
|
||||
typedef SocketOptions = {
|
||||
> SocketOptionsBase,
|
||||
|
||||
/**
|
||||
allows you to specify the existing file descriptor of socket.
|
||||
**/
|
||||
@:optional var fd:Null<Int>;
|
||||
|
||||
/**
|
||||
allow reads on this socket (NOTE: Works only when `fd` is passed)
|
||||
**/
|
||||
@:optional var readable:Bool;
|
||||
|
||||
/**
|
||||
allow writes on this socket (NOTE: Works only when `fd` is passed)
|
||||
**/
|
||||
@:optional var writable:Bool;
|
||||
}
|
||||
|
||||
/**
|
||||
Options for the `Socket.connect` method (TCP version).
|
||||
**/
|
||||
typedef SocketConnectOptionsTcp = {
|
||||
/**
|
||||
Port the client should connect to
|
||||
**/
|
||||
var port:Int;
|
||||
|
||||
/**
|
||||
Host the client should connect to.
|
||||
Defaults to 'localhost'.
|
||||
**/
|
||||
@:optional var host:String;
|
||||
|
||||
/**
|
||||
Local interface to bind to for network connections.
|
||||
**/
|
||||
@:optional var localAddress:String;
|
||||
|
||||
/**
|
||||
Local port to bind to for network connections.
|
||||
**/
|
||||
@:optional var localPort:Int;
|
||||
|
||||
/**
|
||||
Version of IP stack. Defaults to 4.
|
||||
**/
|
||||
@:optional var family:DnsAddressFamily;
|
||||
|
||||
/**
|
||||
Custom lookup function. Defaults to `Dns.lookup`.
|
||||
**/
|
||||
@:optional var lookup:String->DnsLookupOptions->DnsLookupCallbackSingle->Void;
|
||||
}
|
||||
|
||||
/**
|
||||
Options for the `Socket.connect` method (Local domain socket version).
|
||||
**/
|
||||
typedef SocketConnectOptionsUnix = {
|
||||
/**
|
||||
Path the client should connect to
|
||||
**/
|
||||
var path:String;
|
||||
}
|
||||
|
||||
/**
|
||||
Bound address, the address family name and port of the socket as reported by the operating system.
|
||||
**/
|
||||
typedef SocketAdress = {
|
||||
/**
|
||||
Connection port.
|
||||
**/
|
||||
var port:Int;
|
||||
|
||||
/**
|
||||
IP Family.
|
||||
**/
|
||||
var family:SocketAdressFamily;
|
||||
|
||||
/**
|
||||
IP Address.
|
||||
**/
|
||||
var address:String;
|
||||
}
|
||||
|
||||
/**
|
||||
Enumeration of possible socket family values.
|
||||
**/
|
||||
@:enum abstract SocketAdressFamily(String) to String {
|
||||
var IPv4 = "IPv4";
|
||||
var IPv6 = "IPv6";
|
||||
}
|
||||
|
||||
@:jsRequire("net", "Socket")
|
||||
extern class Socket extends js.node.stream.Duplex<Socket> {
|
||||
/**
|
||||
Construct a new socket object.
|
||||
**/
|
||||
function new(?options:SocketOptions);
|
||||
|
||||
/**
|
||||
Opens the connection for a given socket.
|
||||
|
||||
If `port` and `host` are given, then the socket will be opened as a TCP socket,
|
||||
if `host` is omitted, localhost will be assumed.
|
||||
If a `path` is given, the socket will be opened as a unix socket to that path.
|
||||
|
||||
Normally this method is not needed, as `Net.createConnection` opens the socket.
|
||||
Use this only if you are implementing a custom `Socket`.
|
||||
|
||||
This function is asynchronous. When the 'connect' event is emitted the socket is established.
|
||||
If there is a problem connecting, the 'connect' event will not be emitted,
|
||||
the 'error' event will be emitted with the exception
|
||||
|
||||
The `connectListener` parameter will be added as an listener for the 'connect' event.
|
||||
**/
|
||||
@:overload(function(path:String, ?connectListener:Void->Void):Socket {})
|
||||
@:overload(function(port:Int, ?connectListener:Void->Void):Socket {})
|
||||
@:overload(function(port:Int, host:String, ?connectListener:Void->Void):Socket {})
|
||||
function connect(options:EitherType<SocketConnectOptionsTcp, SocketConnectOptionsUnix>, ?connectListener:Void->Void):Socket;
|
||||
|
||||
/**
|
||||
`Socket` has the property that `socket.write` always works. This is to help users get up and running quickly.
|
||||
The computer cannot always keep up with the amount of data that is written to a socket - the network connection
|
||||
simply might be too slow. Node will internally queue up the data written to a socket and send it out over the
|
||||
wire when it is possible. (Internally it is polling on the socket's file descriptor for being writable).
|
||||
|
||||
The consequence of this internal buffering is that memory may grow. This property shows the number of characters
|
||||
currently buffered to be written. (Number of characters is approximately equal to the number of bytes to be written,
|
||||
but the buffer may contain strings, and the strings are lazily encoded, so the exact number of bytes is not known.)
|
||||
|
||||
Users who experience large or growing `bufferSize` should attempt to "throttle" the data flows
|
||||
in their program with `pause` and `resume`.
|
||||
**/
|
||||
var bufferSize:Int;
|
||||
|
||||
/**
|
||||
A boolean value that indicates if the connection is destroyed or not.
|
||||
Once a connection is destroyed no further data can be transferred using it.
|
||||
|
||||
define in Stream/Readable.hx
|
||||
**/
|
||||
// var destroyed(default, null):Bool;
|
||||
|
||||
#if haxe4
|
||||
/**
|
||||
Ensures that no more I/O activity happens on this socket.
|
||||
Only necessary in case of errors (parse error or so).
|
||||
|
||||
If `exception` is specified, an 'error' event will be emitted and
|
||||
any listeners for that event will receive exception as an argument.
|
||||
**/
|
||||
function destroy(?exception:Error):Void;
|
||||
#end
|
||||
|
||||
/**
|
||||
Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket.
|
||||
By default `Socket` do not have a timeout.
|
||||
|
||||
When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed.
|
||||
The user must manually `end` or `destroy` the socket.
|
||||
|
||||
If `timeout` is 0, then the existing idle timeout is disabled.
|
||||
|
||||
The optional `callback` parameter will be added as a one time listener for the 'timeout' event.
|
||||
**/
|
||||
function setTimeout(timeout:Int, ?callback:Void->Void):Void;
|
||||
|
||||
/**
|
||||
Disables the Nagle algorithm.
|
||||
By default TCP connections use the Nagle algorithm, they buffer data before sending it off.
|
||||
Setting true for `noDelay` will immediately fire off data each time `write` is called.
|
||||
`noDelay` defaults to true.
|
||||
**/
|
||||
function setNoDelay(?noDelay:Bool):Void;
|
||||
|
||||
/**
|
||||
Enable/disable keep-alive functionality, and optionally set the initial delay
|
||||
before the first keepalive probe is sent on an idle socket.
|
||||
|
||||
`enable` defaults to false.
|
||||
|
||||
Set `initialDelay` (in milliseconds) to set the delay between the last data packet received and
|
||||
the first keepalive probe.
|
||||
|
||||
Setting 0 for `initialDelay` will leave the value unchanged from the default (or previous) setting.
|
||||
Defaults to 0.
|
||||
**/
|
||||
@:overload(function(?initialDelay:Int):Void {})
|
||||
function setKeepAlive(enable:Bool, ?initialDelay:Int):Void;
|
||||
|
||||
/**
|
||||
Returns the bound address, the address family name and port of the socket as reported by the operating system.
|
||||
**/
|
||||
function address():SocketAdress;
|
||||
|
||||
/**
|
||||
Calling `unref` on a socket will allow the program to exit if this is the only active socket in the event system.
|
||||
If the socket is already `unref`d calling `unref` again will have no effect.
|
||||
**/
|
||||
function unref():Socket;
|
||||
|
||||
/**
|
||||
Opposite of `unref`, calling `ref` on a previously `unref`d socket will not let the program exit
|
||||
if it's the only socket left (the default behavior).
|
||||
If the socket is `ref`d calling `ref` again will have no effect.
|
||||
**/
|
||||
function ref():Socket;
|
||||
|
||||
/**
|
||||
The string representation of the remote IP address.
|
||||
For example, '74.125.127.100' or '2001:4860:a005::68'.
|
||||
**/
|
||||
var remoteAddress(default, null):String;
|
||||
|
||||
/**
|
||||
The string representation of the remote IP family.
|
||||
'IPv4' or 'IPv6'.
|
||||
**/
|
||||
var remoteFamily(default, null):SocketAdressFamily;
|
||||
|
||||
/**
|
||||
The numeric representation of the remote port. For example, 80 or 21.
|
||||
**/
|
||||
var remotePort(default, null):Int;
|
||||
|
||||
/**
|
||||
The string representation of the local IP address the remote client is connecting on.
|
||||
For example, if you are listening on '0.0.0.0' and the client connects on '192.168.1.1',
|
||||
the value would be '192.168.1.1'.
|
||||
**/
|
||||
var localAddress(default, null):String;
|
||||
|
||||
/**
|
||||
The numeric representation of the local port. For example, 80 or 21.
|
||||
**/
|
||||
var localPort(default, null):Int;
|
||||
|
||||
/**
|
||||
The amount of received bytes.
|
||||
**/
|
||||
var bytesRead(default, null):Int;
|
||||
|
||||
/**
|
||||
The amount of bytes sent.
|
||||
**/
|
||||
var bytesWritten(default, null):Int;
|
||||
|
||||
/**
|
||||
Always true for TLSSocket instances.
|
||||
|
||||
May be used to distinguish TLS sockets from regular ones.
|
||||
**/
|
||||
var encrypted(default, null):Bool;
|
||||
}
|
Reference in New Issue
Block a user