mirror of https://github.com/nodejs/node.git
cluster: support setting data on shared server
If `obj` given to `cluster._getServer` has `_setServerData` or `_getServerData` methods, the data will be synchronized across workers and stored in master.pull/5010/head
parent
44ed42bd97
commit
509cfbc2b7
|
@ -384,8 +384,15 @@ function masterInit() {
|
|||
message.backlog,
|
||||
message.fd);
|
||||
}
|
||||
if (!handle.data) handle.data = message.data;
|
||||
|
||||
// Set custom server data
|
||||
handle.add(worker, function(errno, reply, handle) {
|
||||
reply = util._extend({ ack: message.seq, key: key }, reply);
|
||||
reply = util._extend({
|
||||
ack: message.seq,
|
||||
key: key,
|
||||
data: handles[key].data
|
||||
}, reply);
|
||||
if (errno) {
|
||||
reply.errno = errno;
|
||||
delete handles[key]; // Gives other workers a chance to retry.
|
||||
|
@ -447,9 +454,14 @@ function workerInit() {
|
|||
address: address,
|
||||
port: port,
|
||||
act: 'queryServer',
|
||||
fd: fd
|
||||
fd: fd,
|
||||
data: null
|
||||
};
|
||||
// Set custom data on handle (i.e. tls tickets key)
|
||||
if (obj._getServerData) message.data = obj._getServerData();
|
||||
send(message, function(reply, handle) {
|
||||
if (obj._setServerData) obj._setServerData(reply.data);
|
||||
|
||||
if (handle)
|
||||
shared(reply, handle, cb); // Shared listen socket.
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue