mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 17:59:50 +02:00
fix(adb): read socket too slow can cause data loss
This commit is contained in:
parent
dce44ae9ac
commit
1aa7a92d2c
7 changed files with 190 additions and 164 deletions
|
@ -87,20 +87,8 @@ export class AdbPacketDispatcher implements Closeable {
|
|||
await this.#handleClose(packet);
|
||||
break;
|
||||
case AdbCommand.Write:
|
||||
if (this.#sockets.has(packet.arg1)) {
|
||||
await this.#sockets
|
||||
.get(packet.arg1)!
|
||||
.enqueue(packet.payload);
|
||||
await this.sendPacket(
|
||||
AdbCommand.OK,
|
||||
packet.arg1,
|
||||
packet.arg0,
|
||||
);
|
||||
break;
|
||||
}
|
||||
throw new Error(
|
||||
`Unknown local socket id: ${packet.arg1}`,
|
||||
);
|
||||
await this.#handleWrite(packet);
|
||||
break;
|
||||
case AdbCommand.Open:
|
||||
await this.#handleOpen(packet);
|
||||
break;
|
||||
|
@ -200,6 +188,17 @@ export class AdbPacketDispatcher implements Closeable {
|
|||
// the device may also respond with two `CLSE` packets.
|
||||
}
|
||||
|
||||
async #handleWrite(packet: AdbPacketData) {
|
||||
const socket = this.#sockets.get(packet.arg1);
|
||||
if (!socket) {
|
||||
throw new Error(`Unknown local socket id: ${packet.arg1}`);
|
||||
}
|
||||
|
||||
await socket.enqueue(packet.payload);
|
||||
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
||||
return;
|
||||
}
|
||||
|
||||
addReverseTunnel(service: string, handler: AdbIncomingSocketHandler) {
|
||||
this.#incomingSocketHandlers.set(service, handler);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue