Use persistent dgram socket client.

refs #135
This commit is contained in:
softsimon 2020-10-13 16:03:03 +07:00
parent 04ac820ed7
commit 4a14085908
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -52,6 +52,7 @@ class Logger {
private fac: any;
private loghost: string;
private logport: number;
private client: dgram.Socket;
constructor(fac) {
let prio;
@ -63,6 +64,7 @@ class Logger {
this.addprio(prio);
}
}
this.client = dgram.createSocket('udp4');
}
private addprio(prio): void {
@ -118,14 +120,12 @@ class Logger {
}
private syslog(msg) {
let client, msgbuf;
let msgbuf;
msgbuf = Buffer.from(msg);
client = dgram.createSocket('udp4');
client.send(msgbuf, 0, msgbuf.length, this.logport, this.loghost, function(err, bytes) {
this.client.send(msgbuf, 0, msgbuf.length, this.logport, this.loghost, function(err, bytes) {
if (err) {
console.log(err);
}
client.close();
});
}