Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
fix tcp bug
Browse files Browse the repository at this point in the history
  • Loading branch information
takayama-lily committed Apr 10, 2021
1 parent b78abc8 commit cb728c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
20 changes: 11 additions & 9 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class Client extends net.Socket {
sent_msg_cnt: 0,
};

data_cache = BUF0;

constructor(uin, config) {
super();
this.uin = uin;
Expand Down Expand Up @@ -131,7 +133,7 @@ class Client extends net.Socket {
this.logger.error(err.message);
});
this.on("close", () => {
this.read();
this.data_cache = BUF0;
if (this.remoteAddress)
this.logger.mark(`${this.remoteAddress}:${this.remotePort} closed`);
this.stopHeartbeat();
Expand All @@ -146,12 +148,13 @@ class Client extends net.Socket {
}
this.status = Client.OFFLINE;
});
this.on("readable", () => {
while (this.readableLength > 4) {
let len_buf = this.read(4);
let len = len_buf.readInt32BE();
if (this.readableLength >= len - 4) {
const packet = this.read(len - 4);
this.on("data", (data) => {
this.data_cache = Buffer.concat([this.data_cache, data]);
while (this.data_cache.length > 4) {
let len = this.data_cache.readUInt32BE();
if (this.data_cache.length >= len) {
const packet = this.data_cache.slice(4, len);
this.data_cache = this.data_cache.slice(len);
++this.stat.recv_pkt_cnt;
try {
core.parseIncomingPacket.call(this, packet);
Expand All @@ -160,7 +163,6 @@ class Client extends net.Socket {
this.em("internal.exception", e);
}
} else {
this.unshift(len_buf);
break;
}
}
Expand Down Expand Up @@ -210,7 +212,7 @@ class Client extends net.Socket {
this.connect(port, ip, () => {
this.status = Client.INIT;
this.logger.mark(`${this.remoteAddress}:${this.remotePort} connected`);
this.resume();
// this.resume();
callback();
});
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oicq",
"version": "1.15.0",
"upday": "2021/4/10",
"version": "1.15.1",
"upday": "2021/4/11",
"description": "QQ protocol!",
"main": "client.js",
"types": "client.d.ts",
Expand Down

0 comments on commit cb728c5

Please sign in to comment.