Skip to content

Commit a99cd80

Browse files
committed
Remove deprecated API, defensive, tentative fix of rescript-lang#2974
1 parent f1044e0 commit a99cd80

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lib/bsb

+14-10
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,16 @@ function notifyClients() {
3232
wsClients = wsClients.filter(x => !x.closed && !x.socket.destroyed )
3333
var wsClientsLen = wsClients.length
3434
dlog(`Alive sockets number: ${wsClientsLen}`)
35-
for (var i = 0; i < wsClientsLen; ++ i ) {
36-
// in reverse order, the last pushed get notified earlier
37-
var client = wsClients[wsClientsLen - i - 1]
38-
if (!client.closed) {
39-
client.sendText(
40-
JSON.stringify(
35+
var data = JSON.stringify(
4136
{
4237
LAST_SUCCESS_BUILD_STAMP: LAST_SUCCESS_BUILD_STAMP
4338
}
4439
)
45-
46-
)
40+
for (var i = 0; i < wsClientsLen; ++ i ) {
41+
// in reverse order, the last pushed get notified earlier
42+
var client = wsClients[wsClientsLen - i - 1]
43+
if (!client.closed) {
44+
client.sendText(data)
4745
}
4846
}
4947
}
@@ -55,6 +53,9 @@ function setUpWebSocket() {
5553
.on('upgrade', function (req, socket, upgradeHead) {
5654
dlog("connection opened");
5755
var ws = new WebSocket(req, socket, upgradeHead);
56+
socket.on("error",function (err){
57+
dlog(`Socket Error ${err}`)
58+
})
5859
wsClients.push(ws)
5960
})
6061
.on('error', function (err) {
@@ -147,7 +148,10 @@ if (watch_mode) {
147148
*/
148149
var watchers = [];
149150

150-
151+
function onUncaughtException (err){
152+
console.error("Uncaught Exception", err)
153+
process.exit(1)
154+
}
151155
function onExit() {
152156
try {
153157
fs.unlinkSync(lockFileName)
@@ -180,7 +184,7 @@ if (watch_mode) {
180184
process.on('SIGUSR2', onExit)
181185
process.on('SIGTERM', onExit)
182186
process.on('SIGHUP', onExit)
183-
process.on('uncaughtException', onExit)
187+
process.on('uncaughtException', onUncaughtException)
184188
process.stdin.on('close', onExit)
185189
// close when stdin stops
186190
if (os.platform() !== "win32") {

lib/minisocket.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ function encodeMessage(opcode, payload) {
3939
// server does not mask frames
4040
var length = payload.length;
4141
if (length < 126) {
42-
buf = new Buffer(payload.length + 2 + 0);
42+
buf = Buffer.allocUnsafe(payload.length + 2 + 0);
4343
// zero extra bytes
4444
b2 |= length;
4545
buf.writeUInt8(b1, 0);
4646
buf.writeUInt8(b2, 1);
4747
payload.copy(buf, 2);
4848
} else if (length < (1 << 16)) {
49-
buf = new Buffer(payload.length + 2 + 2);
49+
buf = Buffer.allocUnsafe(payload.length + 2 + 2);
5050
// two bytes extra
5151
b2 |= 126;
5252
buf.writeUInt8(b1, 0);
@@ -55,7 +55,7 @@ function encodeMessage(opcode, payload) {
5555
buf.writeUInt16BE(length, 2);
5656
payload.copy(buf, 4);
5757
} else {
58-
buf = new Buffer(payload.length + 2 + 8);
58+
buf = Buffer.allocUnsafe(payload.length + 2 + 8);
5959
// eight bytes extra
6060
b2 |= 127;
6161
buf.writeUInt8(b1, 0);
@@ -87,7 +87,7 @@ class MiniWebSocket {
8787
});
8888
};
8989
sendText(obj) {
90-
this.socket.write(encodeMessage(opcodes.TEXT,new Buffer(obj, "utf8")))
90+
this.socket.write(encodeMessage(opcodes.TEXT,Buffer.from(obj, "utf8")))
9191
};
9292
}
9393
exports.MiniWebSocket = MiniWebSocket

0 commit comments

Comments
 (0)