mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
handle partial socket data
This commit is contained in:
@@ -51,6 +51,7 @@ export class StratumV1Client {
|
|||||||
public noFee: boolean;
|
public noFee: boolean;
|
||||||
public hashRate: number;
|
public hashRate: number;
|
||||||
|
|
||||||
|
private buffer: string = '';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly socket: Socket,
|
public readonly socket: Socket,
|
||||||
@@ -65,8 +66,11 @@ export class StratumV1Client {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
this.socket.on('data', (data: Buffer) => {
|
this.socket.on('data', (data: Buffer) => {
|
||||||
data.toString()
|
this.buffer += data.toString();
|
||||||
.split('\n')
|
let lines = this.buffer.split('\n');
|
||||||
|
this.buffer = lines.pop() || ''; // Save the last part of the data (incomplete line) to the buffer
|
||||||
|
|
||||||
|
lines
|
||||||
.filter(m => m.length > 0)
|
.filter(m => m.length > 0)
|
||||||
.forEach(async (m) => {
|
.forEach(async (m) => {
|
||||||
try {
|
try {
|
||||||
@@ -75,7 +79,7 @@ export class StratumV1Client {
|
|||||||
await this.socket.end();
|
await this.socket.end();
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user