Example #1
0
        public NamedPipeWorker(IServiceProvider provider, MessagePipeInterprocessNamedPipeOptions options, IAsyncPublisher <IInterprocessKey, IInterprocessValue> publisher)
        {
            this.pipeName = options.PipeName;
            this.provider = provider;
            this.cancellationTokenSource = new CancellationTokenSource();
            this.options   = options;
            this.publisher = publisher;

            this.server = CreateLazyServerStream();

            this.client = new Lazy <NamedPipeClientStream>(() =>
            {
                return(new NamedPipeClientStream(options.ServerName, options.PipeName, PipeDirection.InOut, PipeOptions.Asynchronous));
            });

#if !UNITY_2018_3_OR_NEWER
            this.channel = Channel.CreateUnbounded <byte[]>(new UnboundedChannelOptions()
            {
                SingleReader = true,
                SingleWriter = false,
                AllowSynchronousContinuations = true
            });
#else
            this.channel = Channel.CreateSingleConsumerUnbounded <byte[]>();
#endif

            if (options.HostAsServer != null && options.HostAsServer.Value)
            {
                StartReceiver();
            }
        }
Example #2
0
        public static ReturnType AddMessagePipeNamedPipeInterprocess(this IServiceCollection services, string pipeName, Action <MessagePipeInterprocessNamedPipeOptions> configure)
        {
            var options = new MessagePipeInterprocessNamedPipeOptions(pipeName);

            configure(options);

            services.AddSingleton(options);
            services.Add(typeof(NamedPipeWorker), options.InstanceLifetime);

#if !UNITY_2018_3_OR_NEWER
            services.Add(typeof(IDistributedPublisher <,>), typeof(NamedPipeDistributedPublisher <,>), InstanceLifetime.Singleton);
            services.Add(typeof(IDistributedSubscriber <,>), typeof(NamedPipeDistributedSubscriber <,>), InstanceLifetime.Singleton);
            services.Add(typeof(IRemoteRequestHandler <,>), typeof(NamedPipeRemoteRequestHandler <,>), options.InstanceLifetime);
            return(services);
#else
            AddAsyncMessageBroker <IInterprocessKey, IInterprocessValue>(services, options);
            return(options);
#endif
        }