diff --git a/src/Microsoft.AspNetCore.NodeServices/Configuration.cs b/src/Microsoft.AspNetCore.NodeServices/Configuration.cs index 51325d4..d24a7e3 100644 --- a/src/Microsoft.AspNetCore.NodeServices/Configuration.cs +++ b/src/Microsoft.AspNetCore.NodeServices/Configuration.cs @@ -41,8 +41,6 @@ namespace Microsoft.AspNetCore.NodeServices return new HttpNodeInstance(options.ProjectPath, /* port */ 0, watchFileExtensions); case NodeHostingModel.Socket: return new SocketNodeInstance(options.ProjectPath, watchFileExtensions); - case NodeHostingModel.InputOutputStream: - return new InputOutputStreamNodeInstance(options.ProjectPath); default: throw new ArgumentException("Unknown hosting model: " + options.HostingModel); } diff --git a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-stream.js b/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-stream.js deleted file mode 100644 index 9d9e792..0000000 --- a/src/Microsoft.AspNetCore.NodeServices/Content/Node/entrypoint-stream.js +++ /dev/null @@ -1,23 +0,0 @@ -var path = require('path'); -var readline = require('readline'); -var invocationPrefix = 'invoke:'; - -function invocationCallback(errorValue, successValue) { - if (errorValue) { - throw new Error('InputOutputStreamHost doesn\'t support errors. Got error: ' + errorValue.toString()); - } else { - var serializedResult = JSON.stringify(successValue); - console.log(serializedResult); - } -} - -readline.createInterface({ input: process.stdin }).on('line', function (message) { - if (message && message.substring(0, invocationPrefix.length) === invocationPrefix) { - var invocation = JSON.parse(message.substring(invocationPrefix.length)); - var invokedModule = require(path.resolve(process.cwd(), invocation.moduleName)); - var func = invocation.exportedFunctionName ? invokedModule[invocation.exportedFunctionName] : invokedModule; - func.apply(null, [invocationCallback].concat(invocation.args)); - } -}); - -console.log('[Microsoft.AspNetCore.NodeServices:Listening]'); // The .NET app waits for this signal before sending any invocations diff --git a/src/Microsoft.AspNetCore.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs b/src/Microsoft.AspNetCore.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs deleted file mode 100644 index ffa2cdc..0000000 --- a/src/Microsoft.AspNetCore.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Diagnostics; -using System.Threading; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; - -namespace Microsoft.AspNetCore.NodeServices -{ - /// - /// This is just to demonstrate that other transports are possible. This implementation is extremely - /// dubious - if the Node-side code fails to conform to the expected protocol in any way (e.g., has an - /// error), then it will just hang forever. So don't use this. - /// - /// But it's fast - the communication round-trip time is about 0.2ms (tested on OS X on a recent machine), - /// versus 2-3ms for the HTTP transport. - /// - /// Instead of directly using stdin/stdout, we could use either regular sockets (TCP) or use named pipes - /// on Windows and domain sockets on Linux / OS X, but either way would need a system for framing the - /// requests, associating them with responses, and scheduling use of the comms channel. - /// - /// - internal class InputOutputStreamNodeInstance : OutOfProcessNodeInstance - { - private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver() - }; - - private TaskCompletionSource _currentInvocationResult; - private readonly SemaphoreSlim _invocationSemaphore = new SemaphoreSlim(1); - - public InputOutputStreamNodeInstance(string projectPath) - : base( - EmbeddedResourceReader.Read( - typeof(InputOutputStreamNodeInstance), - "/Content/Node/entrypoint-stream.js"), - projectPath) - { - } - - public override async Task Invoke(NodeInvocationInfo invocationInfo) - { - await _invocationSemaphore.WaitAsync(); - try - { - await EnsureReady(); - - var payloadJson = JsonConvert.SerializeObject(invocationInfo, JsonSerializerSettings); - var nodeProcess = NodeProcess; - _currentInvocationResult = new TaskCompletionSource(); - nodeProcess.StandardInput.Write("\ninvoke:"); - nodeProcess.StandardInput.WriteLine(payloadJson); // WriteLineAsync isn't supported cross-platform - var resultString = await _currentInvocationResult.Task; - return JsonConvert.DeserializeObject(resultString); - } - finally - { - _invocationSemaphore.Release(); - _currentInvocationResult = null; - } - } - - protected override void OnOutputDataReceived(string outputData) - { - if (_currentInvocationResult != null) - { - _currentInvocationResult.SetResult(outputData); - } - else - { - base.OnOutputDataReceived(outputData); - } - } - } -} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs b/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs index 1f65c60..1a8a5e1 100644 --- a/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs +++ b/src/Microsoft.AspNetCore.NodeServices/HostingModels/OutOfProcessNodeInstance.cs @@ -27,23 +27,13 @@ namespace Microsoft.AspNetCore.NodeServices _projectPath = projectPath; _commandLineArguments = commandLineArguments ?? string.Empty; } - + public string CommandLineArguments { get { return _commandLineArguments; } set { _commandLineArguments = value; } } - protected Process NodeProcess - { - get - { - // This is only exposed to support the unreliable InputOutputStreamNodeInstance, which is just to verify that - // other hosting/transport mechanisms are possible. This shouldn't really be exposed, and will be removed. - return this._nodeProcess; - } - } - public Task Invoke(string moduleName, params object[] args) => InvokeExport(moduleName, null, args); diff --git a/src/Microsoft.AspNetCore.NodeServices/NodeHostingModel.cs b/src/Microsoft.AspNetCore.NodeServices/NodeHostingModel.cs index d5b7b45..eacca81 100644 --- a/src/Microsoft.AspNetCore.NodeServices/NodeHostingModel.cs +++ b/src/Microsoft.AspNetCore.NodeServices/NodeHostingModel.cs @@ -3,7 +3,6 @@ namespace Microsoft.AspNetCore.NodeServices public enum NodeHostingModel { Http, - InputOutputStream, Socket, } }