diff --git a/src/net.cc b/src/net.cc index c11a5392d2..6a254ec8b8 100644 --- a/src/net.cc +++ b/src/net.cc @@ -437,7 +437,7 @@ Connection::OnReceive (const void *buf, size_t len) // raw encoding Local array = Array::New(len); for (size_t i = 0; i < len; i++) { - char val = static_cast(buf)[i]; + unsigned char val = static_cast(buf)[i]; array->Set(Integer::New(i), Integer::New(val)); } argv[0] = array; diff --git a/test/mjsunit/test-tcp-raw.js b/test/mjsunit/test-tcp-raw.js new file mode 100644 index 0000000000..0acfc8e180 --- /dev/null +++ b/test/mjsunit/test-tcp-raw.js @@ -0,0 +1,47 @@ +include("mjsunit.js"); +PORT = 23123; + +var echoServer = node.tcp.createServer(function (connection) { + connection.addListener("receive", function (chunk) { + connection.send(chunk, "raw"); + }); + connection.addListener("eof", function () { + connection.close(); + }); +}); +echoServer.listen(PORT); + +var recv = []; +var j = 0; + +function onLoad () { + var c = node.tcp.createConnection(PORT); + + c.addListener("receive", function (chunk) { + if (++j < 256) { + c.send([j], "raw"); + } else { + c.close(); + } + for (var i = 0; i < chunk.length; i++) { + recv.push(chunk[i]); + } + }); + + c.addListener("connect", function () { + c.send([j], "raw"); + }); + + c.addListener("disconnect", function () { + p(recv); + echoServer.close(); + }); +}; + +function onExit () { + var expected = []; + for (var i = 0; i < 256; i++) { + expected.push(i); + } + assertEquals(expected, recv); +}