| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,15 +2,15 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ArrayIsArray, | |
| 5 | - ArrayPrototypePush, | ||
| 6 | - ArrayPrototypeShift, | ||
| 7 | 5 | Boolean, | |
| 6 | + ObjectCreate, | ||
| 8 | 7 | SafeMap, | |
| 9 | 8 | } = primordials; | |
| 10 | 9 | ||
| 11 | 10 | const assert = require('internal/assert'); | |
| 12 | 11 | const net = require('net'); | |
| 13 | 12 | const { sendHelper } = require('internal/cluster/utils'); | |
| 13 | + const { append, init, isEmpty, peek, remove } = require('internal/linkedlist'); | ||
| 14 | 14 | const { constants } = internalBinding('tcp_wrap'); | |
| 15 | 15 | ||
| 16 | 16 | module.exports = RoundRobinHandle; | |
@@ -19,7 +19,7 @@ function RoundRobinHandle(key, address, { port, fd, flags }) { | |||
| 19 | 19 | this.key = key; | |
| 20 | 20 | this.all = new SafeMap(); | |
| 21 | 21 | this.free = new SafeMap(); | |
| 22 | - this.handles = []; | ||
| 22 | + this.handles = init(ObjectCreate(null)); | ||
| 23 | 23 | this.handle = null; | |
| 24 | 24 | this.server = net.createServer(assert.fail); | |
| 25 | 25 | ||
@@ -81,18 +81,19 @@ RoundRobinHandle.prototype.remove = function(worker) { | |||
| 81 | 81 | if (this.all.size !== 0) | |
| 82 | 82 | return false; | |
| 83 | 83 | ||
| 84 | - for (const handle of this.handles) { | ||
| 84 | + while (!isEmpty(this.handles)) { | ||
| 85 | + const handle = peek(this.handles); | ||
| 85 | 86 | handle.close(); | |
| 87 | + remove(handle); | ||
| 86 | 88 | } | |
| 87 | - this.handles = []; | ||
| 88 | 89 | ||
| 89 | 90 | this.handle.close(); | |
| 90 | 91 | this.handle = null; | |
| 91 | 92 | return true; | |
| 92 | 93 | }; | |
| 93 | 94 | ||
| 94 | 95 | RoundRobinHandle.prototype.distribute = function(err, handle) { | |
| 95 | - ArrayPrototypePush(this.handles, handle); | ||
| 96 | + append(this.handles, handle); | ||
| 96 | 97 | // eslint-disable-next-line node-core/no-array-destructuring | |
| 97 | 98 | const [ workerEntry ] = this.free; // this.free is a SafeMap | |
| 98 | 99 | ||
@@ -108,13 +109,15 @@ RoundRobinHandle.prototype.handoff = function(worker) { | |||
| 108 | 109 | return; // Worker is closing (or has closed) the server. | |
| 109 | 110 | } | |
| 110 | 111 | ||
| 111 | - const handle = ArrayPrototypeShift(this.handles); | ||
| 112 | + const handle = peek(this.handles); | ||
| 112 | 113 | ||
| 113 | - if (handle === undefined) { | ||
| 114 | + if (handle === null) { | ||
| 114 | 115 | this.free.set(worker.id, worker); // Add to ready queue again. | |
| 115 | 116 | return; | |
| 116 | 117 | } | |
| 117 | 118 | ||
| 119 | + remove(handle); | ||
| 120 | + | ||
| 118 | 121 | const message = { act: 'newconn', key: this.key }; | |
| 119 | 122 | ||
| 120 | 123 | sendHelper(worker.process, message, handle, (reply) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | function init(list) { | |
| 4 | 4 | list._idleNext = list; | |
| 5 | 5 | list._idlePrev = list; | |
| 6 | + return list; | ||
| 6 | 7 | } | |
| 7 | 8 | ||
| 8 | 9 | // Show the most idle item. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments