mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
read full lines of json-rpc from clients (#46)
Lgtm, thanks for your contribution
This commit is contained in:
@@ -7,6 +7,7 @@ import * as crypto from 'crypto';
|
|||||||
import { Socket } from 'net';
|
import { Socket } from 'net';
|
||||||
import { firstValueFrom, Subscription } from 'rxjs';
|
import { firstValueFrom, Subscription } from 'rxjs';
|
||||||
import { clearInterval } from 'timers';
|
import { clearInterval } from 'timers';
|
||||||
|
import { createInterface } from 'readline';
|
||||||
|
|
||||||
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
|
import { AddressSettingsService } from '../ORM/address-settings/address-settings.service';
|
||||||
import { BlocksService } from '../ORM/blocks/blocks.service';
|
import { BlocksService } from '../ORM/blocks/blocks.service';
|
||||||
@@ -64,19 +65,19 @@ export class StratumV1Client {
|
|||||||
private readonly addressSettingsService: AddressSettingsService
|
private readonly addressSettingsService: AddressSettingsService
|
||||||
) {
|
) {
|
||||||
|
|
||||||
this.socket.on('data', (data: Buffer) => {
|
const rl = createInterface({
|
||||||
data.toString()
|
input: this.socket
|
||||||
.split('\n')
|
})
|
||||||
.filter(m => m.length > 0)
|
|
||||||
.forEach(async (m) => {
|
rl.on("line", async (line) => {
|
||||||
try {
|
try {
|
||||||
await this.handleMessage(m);
|
await this.handleMessage(line);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.socket.end();
|
await this.socket.end();
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
rl.on('error', async (error: Error) => { });
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user