Server: Force data to be sent ahead of a write queue
[KiwiIRC.git] / server / irc / connection.js
index 00822f719eef5bec447bf667a13186b46584f2f9..d8bf8048f708464fb155b524ab8d41e1bfb9f84f 100644 (file)
@@ -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();
 };