mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Remove obsolete InputOutputStream transport, now that the Stream transport is implemented
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <seealso cref="Microsoft.AspNetCore.NodeServices.OutOfProcessNodeInstance" />
|
||||
internal class InputOutputStreamNodeInstance : OutOfProcessNodeInstance
|
||||
{
|
||||
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
||||
};
|
||||
|
||||
private TaskCompletionSource<string> _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<T> Invoke<T>(NodeInvocationInfo invocationInfo)
|
||||
{
|
||||
await _invocationSemaphore.WaitAsync();
|
||||
try
|
||||
{
|
||||
await EnsureReady();
|
||||
|
||||
var payloadJson = JsonConvert.SerializeObject(invocationInfo, JsonSerializerSettings);
|
||||
var nodeProcess = NodeProcess;
|
||||
_currentInvocationResult = new TaskCompletionSource<string>();
|
||||
nodeProcess.StandardInput.Write("\ninvoke:");
|
||||
nodeProcess.StandardInput.WriteLine(payloadJson); // WriteLineAsync isn't supported cross-platform
|
||||
var resultString = await _currentInvocationResult.Task;
|
||||
return JsonConvert.DeserializeObject<T>(resultString);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_invocationSemaphore.Release();
|
||||
_currentInvocationResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnOutputDataReceived(string outputData)
|
||||
{
|
||||
if (_currentInvocationResult != null)
|
||||
{
|
||||
_currentInvocationResult.SetResult(outputData);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnOutputDataReceived(outputData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<T> Invoke<T>(string moduleName, params object[] args)
|
||||
=> InvokeExport<T>(moduleName, null, args);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
public enum NodeHostingModel
|
||||
{
|
||||
Http,
|
||||
InputOutputStream,
|
||||
Socket,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user