mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 21:51:04 +00:00
Update pipe-ipc.js
This commit is contained in:
parent
c0dc768588
commit
c3435f7aac
|
@ -85,6 +85,10 @@ function CRC32(str) {
|
||||||
return ((crc ^ (-1)) >>> 0).toString(16).padStart(8, '0');
|
return ((crc ^ (-1)) >>> 0).toString(16).padStart(8, '0');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeProbabilityBit(p) {
|
||||||
|
return !( p > 0.0 ? ( (randomize() / p) > 1.0 ) : true) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
function createFSO() {
|
function createFSO() {
|
||||||
return CreateObject("Scripting.FileSystemObject");
|
return CreateObject("Scripting.FileSystemObject");
|
||||||
}
|
}
|
||||||
|
@ -156,13 +160,18 @@ function PipeIPC() {
|
||||||
this.maxSentences = maxSentences;
|
this.maxSentences = maxSentences;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.waitForRetry = function() {
|
||||||
|
var t = makeProbabilityBit(0.5);
|
||||||
|
if (t > 0) sleep(t);
|
||||||
|
};
|
||||||
|
|
||||||
this.connect = function(pipename, callback) {
|
this.connect = function(pipename, callback) {
|
||||||
if (pipename == "volatile") {
|
if (pipename == "volatile") {
|
||||||
pipename = createUUIDv4().substring(0, 8);
|
pipename = createUUIDv4().substring(0, 8);
|
||||||
}
|
}
|
||||||
this.path = this.path.replace(":pipename", pipename);
|
this.path = this.path.replace(":pipename", pipename);
|
||||||
//this.openWriter();
|
//this.openWriter();
|
||||||
this.openReader();
|
//this.openReader();
|
||||||
//console.info("Opened pipe:", pipename);
|
//console.info("Opened pipe:", pipename);
|
||||||
if (typeof callback === "function") {
|
if (typeof callback === "function") {
|
||||||
callback(this, this.reader, this.writer);
|
callback(this, this.reader, this.writer);
|
||||||
|
@ -217,6 +226,7 @@ function PipeIPC() {
|
||||||
isExistsTmpFile = checkFileExists(this.tmpfile);
|
isExistsTmpFile = checkFileExists(this.tmpfile);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
isExistsTmpFile = false;
|
isExistsTmpFile = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +274,7 @@ function PipeIPC() {
|
||||||
//console.log(e.message);
|
//console.log(e.message);
|
||||||
this.closeWriter();
|
this.closeWriter();
|
||||||
isWritten = false;
|
isWritten = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,10 +299,12 @@ function PipeIPC() {
|
||||||
this.closeRecorder();
|
this.closeRecorder();
|
||||||
this.commit(this.savefile);
|
this.commit(this.savefile);
|
||||||
isRecorded = true;
|
isRecorded = true;
|
||||||
|
this.closeRecorder();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//console.log(e.message);
|
//console.log(e.message);
|
||||||
this.closeRecorder();
|
this.closeRecorder();
|
||||||
isRecorded = false;
|
isRecorded = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +342,7 @@ function PipeIPC() {
|
||||||
done = true;
|
done = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done = false;
|
done = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -350,6 +364,7 @@ function PipeIPC() {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//console.log(e.message);
|
//console.log(e.message);
|
||||||
isCommited = false;
|
isCommited = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +382,9 @@ function PipeIPC() {
|
||||||
this.closeWriter();
|
this.closeWriter();
|
||||||
isFlushed = true;
|
isFlushed = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.closeWriter();
|
||||||
isFlushed = false;
|
isFlushed = false;
|
||||||
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -391,12 +408,14 @@ function PipeIPC() {
|
||||||
|
|
||||||
while (!isRead) {
|
while (!isRead) {
|
||||||
try {
|
try {
|
||||||
|
this.openReader();
|
||||||
text += this._read(this.reader);
|
text += this._read(this.reader);
|
||||||
isRead = true;
|
isRead = true;
|
||||||
this.lastReadTime = this.getCurrentTime();
|
this.lastReadTime = this.getCurrentTime();
|
||||||
|
this.closeReader();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.closeReader();
|
this.closeReader();
|
||||||
this.openReader();
|
this.waitForRetry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +496,7 @@ exports.adSaveCreateNotExist = adSaveCreateNotExist;
|
||||||
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
exports.adSaveCreateOverWrite = adSaveCreateOverWrite;
|
||||||
exports.adModeReadWrite = adModeReadWrite;
|
exports.adModeReadWrite = adModeReadWrite;
|
||||||
|
|
||||||
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.16";
|
exports.VERSIONINFO = "PIPE-based IPC Module (pipe-ipc.js) version 0.1.17";
|
||||||
exports.AUTHOR = "abuse@catswords.net";
|
exports.AUTHOR = "abuse@catswords.net";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user