Created
March 31, 2011 09:01
-
-
Save fkei/896064 to your computer and use it in GitHub Desktop.
Changes in 1.4.01 from 1.4.02, multibyte character "Connection.prototype.write (data)" has stopped working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- lib/ws/connection.js.orig 2011-03-31 16:43:40.000000000 +0900 | |
+++ lib/ws/connection.js 2011-03-31 16:45:33.000000000 +0900 | |
@@ -182,10 +182,10 @@ | |
/*----------------------------------------------- | |
Various utility style functions: | |
-----------------------------------------------*/ | |
-function write(connection, data) { | |
+function write(connection, data, encoding) { | |
debug(connection.id, 'write: ', (new Buffer(data)).inspect()); | |
if (connection._socket.writable) { | |
- return connection._socket.write(data, 'binary'); | |
+ return connection._socket.write(data, encoding); | |
} | |
return false; | |
} | |
@@ -282,7 +282,15 @@ | |
Connection.prototype.write = function(data) { | |
if (this._state === 4) { | |
- return write(this, '\u0000' + data + '\uffff'); | |
+ if( | |
+ write(this, "\u0000", "binary") && | |
+ write(this, data, "utf8") && | |
+ write(this, "\uffff", "binary") | |
+ ) { | |
+ return true; | |
+ } else { | |
+ debug(this.id, "\033[31mERROR: write: "+data); | |
+ } | |
} else { | |
debug(this.id, '\033[31mCould not send.'); | |
} |
I think I may have a better solution for this coming in node-websocket-server 2.0.0, which is currently in the works.
I have also made inquiries with peter griess who gave the original code for writing this data out, in the three sequential writes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node.js v0.4.4 lib / net.js excerpt from the reference
412 if (! Encoding | | encoding == 'utf8' | | encoding == 'utf-8') {
413 / / default to utf8
414 bytesWritten = pool.write (data, 'utf8', pool.used);
415 charsWritten = Buffer._charsWritten;
416} else {
417 bytesWritten = pool.write (data, encoding, pool.used);
418 charsWritten = bytesWritten;
419}