| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f1b26be commit e0ce7cf
32 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ const bench = common.createBenchmark(main, { | |||
| 14 | 14 | dur: [5] | |
| 15 | 15 | }); | |
| 16 | 16 | ||
| 17 | - const TCP = process.binding('tcp_wrap').TCP; | ||
| 17 | + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); | ||
| 18 | 18 | const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; | |
| 19 | 19 | const WriteWrap = process.binding('stream_wrap').WriteWrap; | |
| 20 | 20 | const PORT = common.PORT; | |
@@ -36,7 +36,7 @@ function fail(err, syscall) { | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | function server() { | |
| 39 | - const serverHandle = new TCP(); | ||
| 39 | + const serverHandle = new TCP(TCPConstants.SERVER); | ||
| 40 | 40 | var err = serverHandle.bind('127.0.0.1', PORT); | |
| 41 | 41 | if (err) | |
| 42 | 42 | fail(err, 'bind'); | |
@@ -92,7 +92,7 @@ function client() { | |||
| 92 | 92 | throw new Error(`invalid type: ${type}`); | |
| 93 | 93 | } | |
| 94 | 94 | ||
| 95 | - const clientHandle = new TCP(); | ||
| 95 | + const clientHandle = new TCP(TCPConstants.SOCKET); | ||
| 96 | 96 | const connectReq = new TCPConnectWrap(); | |
| 97 | 97 | const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); | |
| 98 | 98 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ const bench = common.createBenchmark(main, { | |||
| 14 | 14 | dur: [5] | |
| 15 | 15 | }); | |
| 16 | 16 | ||
| 17 | - const TCP = process.binding('tcp_wrap').TCP; | ||
| 17 | + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); | ||
| 18 | 18 | const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; | |
| 19 | 19 | const WriteWrap = process.binding('stream_wrap').WriteWrap; | |
| 20 | 20 | const PORT = common.PORT; | |
@@ -35,7 +35,7 @@ function fail(err, syscall) { | |||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | function server() { | |
| 38 | - const serverHandle = new TCP(); | ||
| 38 | + const serverHandle = new TCP(TCPConstants.SERVER); | ||
| 39 | 39 | var err = serverHandle.bind('127.0.0.1', PORT); | |
| 40 | 40 | if (err) | |
| 41 | 41 | fail(err, 'bind'); | |
@@ -89,7 +89,7 @@ function client() { | |||
| 89 | 89 | throw new Error(`invalid type: ${type}`); | |
| 90 | 90 | } | |
| 91 | 91 | ||
| 92 | - const clientHandle = new TCP(); | ||
| 92 | + const clientHandle = new TCP(TCPConstants.SOCKET); | ||
| 93 | 93 | const connectReq = new TCPConnectWrap(); | |
| 94 | 94 | const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); | |
| 95 | 95 | var bytes = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ const bench = common.createBenchmark(main, { | |||
| 14 | 14 | dur: [5] | |
| 15 | 15 | }); | |
| 16 | 16 | ||
| 17 | - const TCP = process.binding('tcp_wrap').TCP; | ||
| 17 | + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); | ||
| 18 | 18 | const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; | |
| 19 | 19 | const WriteWrap = process.binding('stream_wrap').WriteWrap; | |
| 20 | 20 | const PORT = common.PORT; | |
@@ -35,7 +35,7 @@ function fail(err, syscall) { | |||
| 35 | 35 | } | |
| 36 | 36 | ||
| 37 | 37 | function server() { | |
| 38 | - const serverHandle = new TCP(); | ||
| 38 | + const serverHandle = new TCP(TCPConstants.SERVER); | ||
| 39 | 39 | var err = serverHandle.bind('127.0.0.1', PORT); | |
| 40 | 40 | if (err) | |
| 41 | 41 | fail(err, 'bind'); | |
@@ -107,7 +107,7 @@ function server() { | |||
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | 109 | function client() { | |
| 110 | - const clientHandle = new TCP(); | ||
| 110 | + const clientHandle = new TCP(TCPConstants.SOCKET); | ||
| 111 | 111 | const connectReq = new TCPConnectWrap(); | |
| 112 | 112 | const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); | |
| 113 | 113 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,7 +236,7 @@ resource's constructor. | |||
| 236 | 236 | ```text | |
| 237 | 237 | FSEVENTWRAP, FSREQWRAP, GETADDRINFOREQWRAP, GETNAMEINFOREQWRAP, HTTPPARSER, | |
| 238 | 238 | JSSTREAM, PIPECONNECTWRAP, PIPEWRAP, PROCESSWRAP, QUERYWRAP, SHUTDOWNWRAP, | |
| 239 | - SIGNALWRAP, STATWATCHER, TCPCONNECTWRAP, TCPWRAP, TIMERWRAP, TTYWRAP, | ||
| 239 | + SIGNALWRAP, STATWATCHER, TCPCONNECTWRAP, TCPSERVER, TCPWRAP, TIMERWRAP, TTYWRAP, | ||
| 240 | 240 | UDPSENDWRAP, UDPWRAP, WRITEWRAP, ZLIB, SSLCONNECTION, PBKDF2REQUEST, | |
| 241 | 241 | RANDOMBYTESREQUEST, TLSWRAP, Timeout, Immediate, TickObject | |
| 242 | 242 | ``` | |
@@ -275,13 +275,13 @@ require('net').createServer((conn) => {}).listen(8080); | |||
| 275 | 275 | Output when hitting the server with `nc localhost 8080`: | |
| 276 | 276 | ||
| 277 | 277 | ```console | |
| 278 | - TCPWRAP(2): trigger: 1 execution: 1 | ||
| 278 | + TCPSERVERWRAP(2): trigger: 1 execution: 1 | ||
| 279 | 279 | TCPWRAP(4): trigger: 2 execution: 0 | |
| 280 | 280 | ``` | |
| 281 | 281 | ||
| 282 | - The first `TCPWRAP` is the server which receives the connections. | ||
| 282 | + The `TCPSERVERWRAP` is the server which receives the connections. | ||
| 283 | 283 | ||
| 284 | - The second `TCPWRAP` is the new connection from the client. When a new | ||
| 284 | + The `TCPWRAP` is the new connection from the client. When a new | ||
| 285 | 285 | connection is made the `TCPWrap` instance is immediately constructed. This | |
| 286 | 286 | happens outside of any JavaScript stack (side note: a `executionAsyncId()` of `0` | |
| 287 | 287 | means it's being executed from C++, with no JavaScript stack above it). | |
@@ -354,7 +354,7 @@ require('net').createServer(() => {}).listen(8080, () => { | |||
| 354 | 354 | Output from only starting the server: | |
| 355 | 355 | ||
| 356 | 356 | ```console | |
| 357 | - TCPWRAP(2): trigger: 1 execution: 1 | ||
| 357 | + TCPSERVERWRAP(2): trigger: 1 execution: 1 | ||
| 358 | 358 | TickObject(3): trigger: 2 execution: 1 | |
| 359 | 359 | before: 3 | |
| 360 | 360 | Timeout(4): trigger: 3 execution: 3 | |
@@ -387,7 +387,7 @@ Only using `execution` to graph resource allocation results in the following: | |||
| 387 | 387 | TTYWRAP(6) -> Timeout(4) -> TIMERWRAP(5) -> TickObject(3) -> root(1) | |
| 388 | 388 | ``` | |
| 389 | 389 | ||
| 390 | - The `TCPWRAP` is not part of this graph, even though it was the reason for | ||
| 390 | + The `TCPSERVERWRAP` is not part of this graph, even though it was the reason for | ||
| 391 | 391 | `console.log()` being called. This is because binding to a port without a | |
| 392 | 392 | hostname is a *synchronous* operation, but to maintain a completely asynchronous | |
| 393 | 393 | API the user's callback is placed in a `process.nextTick()`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,8 +34,8 @@ const { Buffer } = require('buffer'); | |||
| 34 | 34 | const debug = util.debuglog('tls'); | |
| 35 | 35 | const { Timer } = process.binding('timer_wrap'); | |
| 36 | 36 | const tls_wrap = process.binding('tls_wrap'); | |
| 37 | - const { TCP } = process.binding('tcp_wrap'); | ||
| 38 | - const { Pipe } = process.binding('pipe_wrap'); | ||
| 37 | + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); | ||
| 38 | + const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); | ||
| 39 | 39 | const errors = require('internal/errors'); | |
| 40 | 40 | const kConnectOptions = Symbol('connect-options'); | |
| 41 | 41 | const kDisableRenegotiation = Symbol('disable-renegotiation'); | |
@@ -398,7 +398,9 @@ TLSSocket.prototype._wrapHandle = function(wrap) { | |||
| 398 | 398 | ||
| 399 | 399 | var options = this._tlsOptions; | |
| 400 | 400 | if (!handle) { | |
| 401 | - handle = options.pipe ? new Pipe() : new TCP(); | ||
| 401 | + handle = options.pipe ? | ||
| 402 | + new Pipe(PipeConstants.SOCKET) : | ||
| 403 | + new TCP(TCPConstants.SOCKET); | ||
| 402 | 404 | handle.owner = this; | |
| 403 | 405 | } | |
| 404 | 406 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ const { createPromise, | |||
| 28 | 28 | promiseResolve, promiseReject } = process.binding('util'); | |
| 29 | 29 | const debug = util.debuglog('child_process'); | |
| 30 | 30 | const { Buffer } = require('buffer'); | |
| 31 | - const { Pipe } = process.binding('pipe_wrap'); | ||
| 31 | + const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); | ||
| 32 | 32 | const { errname } = process.binding('uv'); | |
| 33 | 33 | const child_process = require('internal/child_process'); | |
| 34 | 34 | const { | |
@@ -103,7 +103,7 @@ exports.fork = function(modulePath /*, args, options*/) { | |||
| 103 | 103 | ||
| 104 | 104 | exports._forkChild = function(fd) { | |
| 105 | 105 | // set process.send() | |
| 106 | - var p = new Pipe(true); | ||
| 106 | + var p = new Pipe(PipeConstants.IPC); | ||
| 107 | 107 | p.open(fd); | |
| 108 | 108 | p.unref(); | |
| 109 | 109 | const control = setupChannel(process, p); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ const assert = require('assert'); | |||
| 10 | 10 | ||
| 11 | 11 | const { Process } = process.binding('process_wrap'); | |
| 12 | 12 | const { WriteWrap } = process.binding('stream_wrap'); | |
| 13 | - const { Pipe } = process.binding('pipe_wrap'); | ||
| 13 | + const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); | ||
| 14 | 14 | const { TTY } = process.binding('tty_wrap'); | |
| 15 | 15 | const { TCP } = process.binding('tcp_wrap'); | |
| 16 | 16 | const { UDP } = process.binding('udp_wrap'); | |
@@ -863,7 +863,7 @@ function _validateStdio(stdio, sync) { | |||
| 863 | 863 | }; | |
| 864 | 864 | ||
| 865 | 865 | if (!sync) | |
| 866 | - a.handle = new Pipe(); | ||
| 866 | + a.handle = new Pipe(PipeConstants.SOCKET); | ||
| 867 | 867 | ||
| 868 | 868 | acc.push(a); | |
| 869 | 869 | } else if (stdio === 'ipc') { | |
@@ -876,7 +876,7 @@ function _validateStdio(stdio, sync) { | |||
| 876 | 876 | throw new errors.Error('ERR_IPC_SYNC_FORK'); | |
| 877 | 877 | } | |
| 878 | 878 | ||
| 879 | - ipc = new Pipe(true); | ||
| 879 | + ipc = new Pipe(PipeConstants.IPC); | ||
| 880 | 880 | ipcFd = i; | |
| 881 | 881 | ||
| 882 | 882 | acc.push({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,8 +37,8 @@ const { | |||
| 37 | 37 | ||
| 38 | 38 | const { Buffer } = require('buffer'); | |
| 39 | 39 | const TTYWrap = process.binding('tty_wrap'); | |
| 40 | - const { TCP } = process.binding('tcp_wrap'); | ||
| 41 | - const { Pipe } = process.binding('pipe_wrap'); | ||
| 40 | + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); | ||
| 41 | + const { Pipe, constants: PipeConstants } = process.binding('pipe_wrap'); | ||
| 42 | 42 | const { TCPConnectWrap } = process.binding('tcp_wrap'); | |
| 43 | 43 | const { PipeConnectWrap } = process.binding('pipe_wrap'); | |
| 44 | 44 | const { ShutdownWrap, WriteWrap } = process.binding('stream_wrap'); | |
@@ -57,10 +57,20 @@ const exceptionWithHostPort = util._exceptionWithHostPort; | |||
| 57 | 57 | ||
| 58 | 58 | function noop() {} | |
| 59 | 59 | ||
| 60 | - function createHandle(fd) { | ||
| 60 | + function createHandle(fd, is_server) { | ||
| 61 | 61 | const type = TTYWrap.guessHandleType(fd); | |
| 62 | - if (type === 'PIPE') return new Pipe(); | ||
| 63 | - if (type === 'TCP') return new TCP(); | ||
| 62 | + if (type === 'PIPE') { | ||
| 63 | + return new Pipe( | ||
| 64 | + is_server ? PipeConstants.SERVER : PipeConstants.SOCKET | ||
| 65 | + ); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (type === 'TCP') { | ||
| 69 | + return new TCP( | ||
| 70 | + is_server ? TCPConstants.SERVER : TCPConstants.SOCKET | ||
| 71 | + ); | ||
| 72 | + } | ||
| 73 | + | ||
| 64 | 74 | throw new errors.TypeError('ERR_INVALID_FD_TYPE', type); | |
| 65 | 75 | } | |
| 66 | 76 | ||
@@ -200,7 +210,7 @@ function Socket(options) { | |||
| 200 | 210 | this._handle = options.handle; // private | |
| 201 | 211 | this[async_id_symbol] = getNewAsyncId(this._handle); | |
| 202 | 212 | } else if (options.fd !== undefined) { | |
| 203 | - this._handle = createHandle(options.fd); | ||
| 213 | + this._handle = createHandle(options.fd, false); | ||
| 204 | 214 | this._handle.open(options.fd); | |
| 205 | 215 | this[async_id_symbol] = this._handle.getAsyncId(); | |
| 206 | 216 | // options.fd can be string (since it is user-defined), | |
@@ -1009,7 +1019,9 @@ Socket.prototype.connect = function(...args) { | |||
| 1009 | 1019 | debug('pipe', pipe, path); | |
| 1010 | 1020 | ||
| 1011 | 1021 | if (!this._handle) { | |
| 1012 | - this._handle = pipe ? new Pipe() : new TCP(); | ||
| 1022 | + this._handle = pipe ? | ||
| 1023 | + new Pipe(PipeConstants.SOCKET) : | ||
| 1024 | + new TCP(TCPConstants.SOCKET); | ||
| 1013 | 1025 | initSocketHandle(this); | |
| 1014 | 1026 | } | |
| 1015 | 1027 | ||
@@ -1269,7 +1281,7 @@ function createServerHandle(address, port, addressType, fd) { | |||
| 1269 | 1281 | var isTCP = false; | |
| 1270 | 1282 | if (typeof fd === 'number' && fd >= 0) { | |
| 1271 | 1283 | try { | |
| 1272 | - handle = createHandle(fd); | ||
| 1284 | + handle = createHandle(fd, true); | ||
| 1273 | 1285 | } catch (e) { | |
| 1274 | 1286 | // Not a fd we can listen on. This will trigger an error. | |
| 1275 | 1287 | debug('listen invalid fd=%d:', fd, e.message); | |
@@ -1280,15 +1292,15 @@ function createServerHandle(address, port, addressType, fd) { | |||
| 1280 | 1292 | handle.writable = true; | |
| 1281 | 1293 | assert(!address && !port); | |
| 1282 | 1294 | } else if (port === -1 && addressType === -1) { | |
| 1283 | - handle = new Pipe(); | ||
| 1295 | + handle = new Pipe(PipeConstants.SERVER); | ||
| 1284 | 1296 | if (process.platform === 'win32') { | |
| 1285 | 1297 | var instances = parseInt(process.env.NODE_PENDING_PIPE_INSTANCES); | |
| 1286 | 1298 | if (!isNaN(instances)) { | |
| 1287 | 1299 | handle.setPendingInstances(instances); | |
| 1288 | 1300 | } | |
| 1289 | 1301 | } | |
| 1290 | 1302 | } else { | |
| 1291 | - handle = new TCP(); | ||
| 1303 | + handle = new TCP(TCPConstants.SERVER); | ||
| 1292 | 1304 | isTCP = true; | |
| 1293 | 1305 | } | |
| 1294 | 1306 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,7 @@ namespace node { | |||
| 46 | 46 | V(HTTPPARSER) \ | |
| 47 | 47 | V(JSSTREAM) \ | |
| 48 | 48 | V(PIPECONNECTWRAP) \ | |
| 49 | + V(PIPESERVERWRAP) \ | ||
| 49 | 50 | V(PIPEWRAP) \ | |
| 50 | 51 | V(PROCESSWRAP) \ | |
| 51 | 52 | V(PROMISE) \ | |
@@ -54,6 +55,7 @@ namespace node { | |||
| 54 | 55 | V(SIGNALWRAP) \ | |
| 55 | 56 | V(STATWATCHER) \ | |
| 56 | 57 | V(TCPCONNECTWRAP) \ | |
| 58 | + V(TCPSERVERWRAP) \ | ||
| 57 | 59 | V(TCPWRAP) \ | |
| 58 | 60 | V(TIMERWRAP) \ | |
| 59 | 61 | V(TTYWRAP) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,9 @@ void ConnectionWrap<WrapType, UVType>::OnConnection(uv_stream_t* handle, | |||
| 51 | 51 | if (status == 0) { | |
| 52 | 52 | env->set_init_trigger_async_id(wrap_data->get_async_id()); | |
| 53 | 53 | // Instantiate the client javascript object and handle. | |
| 54 | - Local<Object> client_obj = WrapType::Instantiate(env, wrap_data); | ||
| 54 | + Local<Object> client_obj = WrapType::Instantiate(env, | ||
| 55 | + wrap_data, | ||
| 56 | + WrapType::SOCKET); | ||
| 55 | 57 | ||
| 56 | 58 | // Unwrap the client javascript object. | |
| 57 | 59 | WrapType* wrap; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments