Skip to content
Permalink
Browse files

zlib, feat: reset dataSize when attaching to new stream.

  • Loading branch information...
xicilion committed Jun 24, 2018
1 parent 502b087 commit a8ad13614bca3ed0aabc0024ad0f413571b7fe32
Showing with 31 additions and 1 deletion.
  1. +1 −0 fibjs/include/ZlibStream.h
  2. +30 −1 test/ws_test.js
@@ -104,6 +104,7 @@ class ZlibStream : public Stream_base {
void attach(Stream_base* stm)
{
m_stm = stm;
m_dataSize = 0;
}

public:
@@ -485,7 +485,10 @@ describe('ws', () => {
msg.stream.close();
else if (msg.data === "close")
this.close(3000, "remote");
else
else if (msg.data === "many") {
for (var i = 0; i < 1025; i++)
s.send(new Buffer(1024 * 64));
} else
this.send(msg.data);
};
})
@@ -556,6 +559,32 @@ describe('ws', () => {
s.close();
});

it('many compressed message', () => {
var cnt = 0;
var sz = 0;
var msg;
var s = new ws.Socket("ws://127.0.0.1:" + (8814 + base_port) + "/ws", "test");
s.onopen = () => {
s.send('many');
};

s.onmessage = m => {
cnt++;
sz += m.data.length;
};

s.onerror = e => {
console.error(e);
};

for (var i = 0; i < 1000 && cnt < 1025; i++)
coroutine.sleep(1);

s.close();

assert.equal(sz, 1024 * 1025 * 64);
});

it('send/on("message")', () => {
var httpd = new http.Server(8815 + base_port, {
"/ws": ws.upgrade((s) => {

0 comments on commit a8ad136

Please sign in to comment.
You can’t perform that action at this time.