Skip to content

Commit

Permalink
zlib, feat: reset dataSize when attaching to new stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Jun 24, 2018
1 parent 502b087 commit a8ad136
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions fibjs/include/ZlibStream.h
Expand Up @@ -104,6 +104,7 @@ class ZlibStream : public Stream_base {
void attach(Stream_base* stm)
{
m_stm = stm;
m_dataSize = 0;
}

public:
Expand Down
31 changes: 30 additions & 1 deletion test/ws_test.js
Expand Up @@ -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);
};
})
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit a8ad136

Please sign in to comment.