/**
* 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
/**
- * 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();
};