0
我在寫一個函數來確保節點實例正常關閉。 要做到這一點,我確保我所有的套接字都是unref()
。這是我在做什麼:節點中入站和出站套接字之間的區別
function tidyUp(){
console.log("Closing the server...");
server.close();
console.log("Ordering a hotplate shutdown...");
process.emit('hotplateShutdown');
// This will give time to server.close() to actually work..
setTimeout(function() {
console.log("Calling unref() for all Sockets and for the Server:");
wtf.dump();
var handles = Array.prototype.slice.call(process._getActiveHandles());
handles.forEach((h, i) => {
var name = h.constructor.name;
if(h.unref && typeof h.unref == 'function' & (name == 'Socket' || name == 'Server')){
console.log("Unreffing:", i);
h.unref();
}
});
console.log("After unreffing:");
wtf.dump();
setTimeout(function(){
console.log("This process should soon close");
console.log("Here is the event queue keeping it alive:");
wtf.dump(true);
}, 1000);
}, 1000);
};
我很擔心,因爲服務器還發送電子郵件,和我想要絕對確保所發送的任何確實發送。 基本上是:
「給Socket
對象,你怎麼知道它是入站插槽(一個接收連接,因爲節點的HTTP服務器將打開)或出站套接字(由nodemailer
一個開放的發送電子郵件)。」
我會想要unref()
所有入站套接字,並保持出站的和平,直到所有的電子郵件已發送。
提示?
沒有區別。他們都是插座。你要記住哪個是哪個。 – EJP
我想一個有源IP的主機自己的IP是一個「本地生成」的套接字......對吧? – Merc
編號套接字沒有源IP地址。他們有本地和遠程IP地址。接受的aockets與出站連接的套接字無法區分。 – EJP