| 142 | |
| 143 | // Shared listen socket. |
| 144 | function shared(message, { handle, indexesKey, index }, cb) { |
| 145 | const key = message.key; |
| 146 | // Monkey-patch the close() method so we can keep track of when it's |
| 147 | // closed. Avoids resource leaks when the handle is short-lived. |
| 148 | const close = handle.close; |
| 149 | |
| 150 | handle.close = function() { |
| 151 | send({ act: 'close', key }); |
| 152 | handles.delete(key); |
| 153 | removeIndexesKey(indexesKey, index); |
| 154 | return ReflectApply(close, handle, arguments); |
| 155 | }; |
| 156 | assert(handles.has(key) === false); |
| 157 | handles.set(key, handle); |
| 158 | cb(message.errno, handle); |
| 159 | } |
| 160 | |
| 161 | // Round-robin. Master distributes handles across workers. |
| 162 | function rr(message, { indexesKey, index }, cb) { |