From 56f0f1b936242a7384675749c89e990aef7c0d8b Mon Sep 17 00:00:00 2001 From: Darren Date: Fri, 2 Aug 2013 12:06:33 +0100 Subject: [PATCH] Server: Force data to be sent ahead of a write queue --- server/irc/connection.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/irc/connection.js b/server/irc/connection.js index 00822f7..d8bf804 100644 --- a/server/irc/connection.js +++ b/server/irc/connection.js @@ -263,11 +263,18 @@ IrcConnection.prototype.clientEvent = function (event_name, data, callback) { /** * Write a line of data to the IRCd + * @param data The line of data to be sent + * @param force Write the data now, ignoring any write queue */ -IrcConnection.prototype.write = function (data, callback) { +IrcConnection.prototype.write = function (data, force) { //ENCODE string to encoding of the server encoded_buffer = iconv.encode(data + '\r\n', this.encoding); + if (force) { + this.socket.write(encoded_buffer); + return; + } + this.write_buffer.push(encoded_buffer); // Only flush if we're not writing already @@ -325,11 +332,14 @@ IrcConnection.prototype.flushWriteBuffer = function () { /** - * Close the connection to the IRCd after sending one last line + * Close the connection to the IRCd after forcing one last line */ IrcConnection.prototype.end = function (data, callback) { + if (!this.socket) + return; + if (data) - this.write(data); + this.write(data, true); this.socket.end(); }; -- 2.25.1