Exemple #1
0
        public TcpWorker(IServiceProvider provider, MessagePipeInterprocessTcpUdsOptions options, IAsyncPublisher <IInterprocessKey, IInterprocessValue> publisher)
        {
            this.provider = provider;
            this.cancellationTokenSource = new CancellationTokenSource();
            this.options   = options;
            this.publisher = publisher;

            this.server = new Lazy <SocketTcpServer>(() =>
            {
                return(SocketTcpServer.ListenUds(options.SocketPath));
            });

            this.client = new Lazy <SocketTcpClient>(() =>
            {
                return(SocketTcpClient.ConnectUds(options.SocketPath));
            });

#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();
            }
        }
Exemple #2
0
        public static ReturnType AddMessagePipeTcpInterprocessUds(this IServiceCollection services, string domainSocketPath, Action <MessagePipeInterprocessTcpUdsOptions> configure)
        {
            var options = new MessagePipeInterprocessTcpUdsOptions(domainSocketPath);

            configure(options);

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

#if !UNITY_2018_3_OR_NEWER
            services.Add(typeof(IDistributedPublisher <,>), typeof(TcpDistributedPublisher <,>), options.InstanceLifetime);
            services.Add(typeof(IDistributedSubscriber <,>), typeof(TcpDistributedSubscriber <,>), options.InstanceLifetime);
            services.Add(typeof(IRemoteRequestHandler <,>), typeof(TcpRemoteRequestHandler <,>), options.InstanceLifetime);
            return(services);
#else
            AddAsyncMessageBroker <IInterprocessKey, IInterprocessValue>(services, options);
            return(options);
#endif
        }