Skip to content

Address #2973 #2996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions lib/bsb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ function notifyClients() {
wsClients = wsClients.filter(x => !x.closed && !x.socket.destroyed )
var wsClientsLen = wsClients.length
dlog(`Alive sockets number: ${wsClientsLen}`)
for (var i = 0; i < wsClientsLen; ++ i ) {
// in reverse order, the last pushed get notified earlier
var client = wsClients[wsClientsLen - i - 1]
if (!client.closed) {
client.sendText(
JSON.stringify(
var data = JSON.stringify(
{
LAST_SUCCESS_BUILD_STAMP: LAST_SUCCESS_BUILD_STAMP
}
)

)
for (var i = 0; i < wsClientsLen; ++ i ) {
// in reverse order, the last pushed get notified earlier
var client = wsClients[wsClientsLen - i - 1]
if (!client.closed) {
client.sendText(data)
}
}
}
Expand All @@ -55,6 +53,9 @@ function setUpWebSocket() {
.on('upgrade', function (req, socket, upgradeHead) {
dlog("connection opened");
var ws = new WebSocket(req, socket, upgradeHead);
socket.on("error",function (err){
dlog(`Socket Error ${err}`)
})
wsClients.push(ws)
})
.on('error', function (err) {
Expand Down Expand Up @@ -147,7 +148,10 @@ if (watch_mode) {
*/
var watchers = [];


function onUncaughtException (err){
console.error("Uncaught Exception", err)
process.exit(1)
}
function onExit() {
try {
fs.unlinkSync(lockFileName)
Expand Down Expand Up @@ -180,7 +184,7 @@ if (watch_mode) {
process.on('SIGUSR2', onExit)
process.on('SIGTERM', onExit)
process.on('SIGHUP', onExit)
process.on('uncaughtException', onExit)
process.on('uncaughtException', onUncaughtException)
process.stdin.on('close', onExit)
// close when stdin stops
if (os.platform() !== "win32") {
Expand Down
8 changes: 4 additions & 4 deletions lib/minisocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ function encodeMessage(opcode, payload) {
// server does not mask frames
var length = payload.length;
if (length < 126) {
buf = new Buffer(payload.length + 2 + 0);
buf = Buffer.allocUnsafe(payload.length + 2 + 0);
// zero extra bytes
b2 |= length;
buf.writeUInt8(b1, 0);
buf.writeUInt8(b2, 1);
payload.copy(buf, 2);
} else if (length < (1 << 16)) {
buf = new Buffer(payload.length + 2 + 2);
buf = Buffer.allocUnsafe(payload.length + 2 + 2);
// two bytes extra
b2 |= 126;
buf.writeUInt8(b1, 0);
Expand All @@ -55,7 +55,7 @@ function encodeMessage(opcode, payload) {
buf.writeUInt16BE(length, 2);
payload.copy(buf, 4);
} else {
buf = new Buffer(payload.length + 2 + 8);
buf = Buffer.allocUnsafe(payload.length + 2 + 8);
// eight bytes extra
b2 |= 127;
buf.writeUInt8(b1, 0);
Expand Down Expand Up @@ -87,7 +87,7 @@ class MiniWebSocket {
});
};
sendText(obj) {
this.socket.write(encodeMessage(opcodes.TEXT,new Buffer(obj, "utf8")))
this.socket.write(encodeMessage(opcodes.TEXT,Buffer.from(obj, "utf8")))
};
}
exports.MiniWebSocket = MiniWebSocket