From 509cfbc2b73e9ef0f732ed12ebdc58546348b9c2 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Sun, 21 Jul 2013 10:09:47 +0700 Subject: [PATCH] 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. --- lib/cluster.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/cluster.js b/lib/cluster.js index 650389278c8..8f27e67c3f4 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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