mirror of https://github.com/embarklabs/embark.git
assign roles so ipc connections don't conflict; fallback if can't connect to ipc
This commit is contained in:
parent
a57bce2a40
commit
c0e559a7d9
|
@ -183,7 +183,7 @@ class Engine {
|
|||
compiler.compile_contracts(contractFiles, cb);
|
||||
});
|
||||
|
||||
this.ipc = new IPC({logger: this.logger});
|
||||
this.ipc = new IPC({logger: this.logger, ipcRole: options.ipcRole});
|
||||
this.registerModule('solidity', {useIpc: options.useIpc, ipc: this.ipc});
|
||||
this.registerModule('vyper');
|
||||
this.registerModule('profiler');
|
||||
|
|
|
@ -6,13 +6,31 @@ class IPC {
|
|||
constructor(options) {
|
||||
this.logger = options.logger;
|
||||
this.socketPath = options.socketPath || fs.dappPath(".embark/embark.ipc");
|
||||
this.ipcRole = options.ipcRole || "server";
|
||||
ipc.config.silent = true;
|
||||
this.connected = false;
|
||||
}
|
||||
|
||||
connect(done) {
|
||||
const self = this;
|
||||
function connecting(socket) {
|
||||
let connectedBefore = false, alreadyDisconnected = false;;
|
||||
ipc.of['embark'].on('connect',function() {
|
||||
done();
|
||||
connectedBefore = true;
|
||||
if (!alreadyDisconnected) {
|
||||
self.connected = true;
|
||||
done();
|
||||
}
|
||||
});
|
||||
ipc.of['embark'].on('disconnect',function() {
|
||||
self.connected = false;
|
||||
ipc.disconnect('embark');
|
||||
|
||||
// we only want to trigger the error callback the first time
|
||||
if (!connectedBefore && !alreadyDisconnected) {
|
||||
alreadyDisconnected = true;
|
||||
done(new Error("no connection found"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -59,6 +77,14 @@ class IPC {
|
|||
ipc.of['embark'].emit('message', {action: action, message: data});
|
||||
}
|
||||
|
||||
isClient() {
|
||||
return this.ipcRole === 'client';
|
||||
}
|
||||
|
||||
isServer() {
|
||||
return this.ipcRole === 'server';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = IPC;
|
||||
|
|
|
@ -10,7 +10,6 @@ class SolcW {
|
|||
constructor(options) {
|
||||
this.logger = options.logger;
|
||||
this.events = options.events;
|
||||
this.useIpc = options.useIpc;
|
||||
this.ipc = options.ipc;
|
||||
this.compilerLoaded = false;
|
||||
this.solcProcess = null;
|
||||
|
@ -18,11 +17,21 @@ class SolcW {
|
|||
|
||||
load_compiler(done) {
|
||||
const self = this;
|
||||
if (self.useIpc) {
|
||||
self.compilerLoaded = true;
|
||||
|
||||
return self.ipc.connect(done);
|
||||
if (self.ipc.isClient()) {
|
||||
return self.ipc.connect((err) => {
|
||||
if (err) {
|
||||
return self.load_compiler_internally(done);
|
||||
}
|
||||
self.compilerLoaded = true;
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
self.load_compiler_internally(done);
|
||||
}
|
||||
|
||||
load_compiler_internally(done) {
|
||||
const self = this;
|
||||
if (this.compilerLoaded) {
|
||||
return done();
|
||||
}
|
||||
|
@ -38,8 +47,10 @@ class SolcW {
|
|||
done();
|
||||
});
|
||||
|
||||
this.ipc.serve();
|
||||
this.ipc.on('compile', self.compile.bind(this));
|
||||
if (this.ipc.isServer()) {
|
||||
this.ipc.serve();
|
||||
this.ipc.on('compile', self.compile.bind(this));
|
||||
}
|
||||
|
||||
this.events.request("version:get:solc", function(solcVersion) {
|
||||
if (solcVersion === currentSolcVersion) {
|
||||
|
@ -64,7 +75,7 @@ class SolcW {
|
|||
const id = uuid();
|
||||
let a = new Date();
|
||||
|
||||
if (this.useIpc) {
|
||||
if (this.ipc.isClient() && this.ipc.connected) {
|
||||
return this.ipc.request('compile', jsonObj, done);
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ class Test {
|
|||
});
|
||||
this.engine.startService("deployment", {
|
||||
trackContracts: false,
|
||||
useIpc: true
|
||||
ipcRole: 'client'
|
||||
});
|
||||
this.engine.startService("codeGenerator");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue