Skip to content
Extraits de code Groupes Projets
Vérifiée Valider b43917fe rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LIB: Update socket to handle errors in logs

parent ab62341a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
2 requêtes de fusion!3Dev kubat,!1Create basic lib
......@@ -20,42 +20,50 @@ class LktClient {
writable: true
};
logger.log("debug", "Creating the lektor client");
logger.debug("Creating the lektor client");
this.m_socket.setTimeout(10);
this.m_socket.setEncoding('utf8');
this.m_socket.on("timeout", () => {
logger.log("error", `Got timeout while connecting to localhost:${this.m_port}`);
logger.error(`Got timeout while connecting to localhost:${this.m_port}`);
this.m_socket.end();
});
this.m_socket.on("ready", () => {
logger.log("debug", `Ready to use socker with localhost:${this.m_port}`);
logger.debug(`Ready to use socker with localhost:${this.m_port}`);
this.m_online = true;
});
this.m_socket.on('data', (data) => {
logger.log("debug", `Recieved "${data.replace(/(\r\n|\n|\r)/gm, "")}"`);
logger.debug(`Recieved "${data.replace(/(\r\n|\n|\r)/gm, "")}"`);
});
this.m_socket.on("end", () => {
logger.log("info", `Disconnected from server localhost:${this.m_port}`);
logger.info(`Disconnected from server localhost:${this.m_port}`);
this.m_online = false;
});
this.m_socket.on('error', (err) => {
logger.error(`${err}`);
if (this.m_online) {
this.m_socket.destroy();
this.m_online = false;
}
});
this.m_socket.on("close", () => {
logger.log("info", `Socket localhost:${this.m_port} closed`);
logger.info(`Socket localhost:${this.m_port} closed`);
this.m_online = false;
});
this.m_socket.connect(sockopt, () => {
logger.log("info", `Socket connected to localhost:${this.m_port}`);
logger.info(`Socket connected to localhost:${this.m_port}`);
this.m_online = true;
});
}
/* Wait for the socket to be connected */
wait() {
logger.log("debug", `Waiting to connect to localhost:${this.m_port}`);
logger.debug(`Waiting to connect to localhost:${this.m_port}`);
var i = 0;
while (! this.m_online) {
}
......@@ -63,8 +71,12 @@ class LktClient {
/* Close the client */
close() {
logger.log("debug", "Requesting socket shutdown");
this.m_socket.destroy();
if (this.m_online) {
logger.debug("Requesting socket shutdown");
this.m_socket.destroy();
} else {
logger.debug("Socket already closed");
}
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter