コード例 #1
0
        private async Task WithServer(
            string testName,
            IIpcOperationExecutor executor,
            Func <MultiplexingServer <Socket>, TcpIpConnectivity, Task> testAction,
            int maxConcurrentClients           = 2,
            int maxConcurrentRequestsPerClient = 10)
        {
            var logger        = VerboseLogger(testName);
            var tcpIpProvider = CreateAndStartTcpIpProvider(logger);
            var server        = new MultiplexingServer <Socket>(
                "TestTcpIpServer(" + testName + ")",
                logger,
                tcpIpProvider,
                maxConcurrentClients,
                maxConcurrentRequestsPerClient);

            server.Start(executor);
            using (server)
            {
                try
                {
                    await testAction(server, tcpIpProvider);
                }
                finally
                {
                    server.RequestStop();
                    await server.Completion;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Starts the client listener server.
        /// </summary>
        public void Start(IIpcOperationExecutor executor)
        {
            Contract.Requires(executor != null);

            m_executor = executor;
            m_clientListener.Start(ClientHandlerAsync);
        }
コード例 #3
0
 /// <summary>
 ///     1. creates a server
 ///     2. starts the server
 ///     3. invokes 'testAction'
 ///     4. shuts down the server
 ///     5. waits for the server to complete.
 /// </summary>
 protected static void WithIpcServer(IIpcProvider provider, IIpcOperationExecutor executor, IServerConfig config, Action <IIpcMoniker, IServer> testAction)
 {
     WithIpcServer(
         provider,
         executor,
         config,
         (moniker, server) =>
     {
         testAction(moniker, server);
         return(Task.FromResult(1));
     }).GetAwaiter().GetResult();
 }
コード例 #4
0
        /// <inheritdoc/>
        public void Start(IIpcOperationExecutor executor)
        {
            Contract.Requires(executor != null);

            m_clientListener.Start(async(client) =>
            {
                using (client)
                    using (var bundle = m_connectivityProvider.GetStreamForClient(client))
                    {
                        await Utils.ReceiveOperationAndExecuteLocallyAsync(bundle, executor, CancellationToken.None);
                    }
            });
        }
コード例 #5
0
        /// <inheritdoc/>
        public void Start(IIpcOperationExecutor executor)
        {
            Contract.Requires(executor != null);

            m_clientListener.Start(async(client) =>
            {
                using (client)
                    using (var bundle = m_connectivityProvider.GetStreamForClient(client))
                    {
                        int id = Interlocked.Increment(ref s_requestIdCounter);
                        await Utils.ReceiveOperationAndExecuteLocallyAsync(id, bundle, executor, CancellationToken.None);
                    }
            });
        }
コード例 #6
0
 private Task WithServerAndClient(
     string testName,
     IIpcOperationExecutor executor,
     Func <MultiplexingServer <Socket>, TcpIpConnectivity, Stream, Task> testAction,
     int maxConcurrentClients           = 2,
     int maxConcurrentRequestsPerClient = 10)
 {
     return(WithServer(
                testName,
                executor,
                maxConcurrentClients: maxConcurrentClients,
                maxConcurrentRequestsPerClient: maxConcurrentRequestsPerClient,
                testAction: (server, tcpIpProvider) => WithClient(tcpIpProvider, stream => testAction(server, tcpIpProvider, stream))));
 }
コード例 #7
0
        /// <summary>
        /// Async version of <see cref="WithIpcServer(IIpcProvider, IIpcOperationExecutor, IServerConfig, Action{IIpcMoniker, IServer})"/>
        /// </summary>
        protected static async Task WithIpcServer(IIpcProvider provider, IIpcOperationExecutor executor, IServerConfig config, Func <IIpcMoniker, IServer, Task> testAction)
        {
            var moniker = provider.CreateNewMoniker();
            var server  = provider.GetServer(provider.RenderConnectionString(moniker), config);

            server.Start(executor);
            try
            {
                await testAction(moniker, server);
            }
            finally
            {
                server.RequestStop();
                await server.Completion;
                server.Dispose();
            }
        }
コード例 #8
0
ファイル: DummyIpcProvider.cs プロジェクト: kittinap/kunnjae
 public void Start(IIpcOperationExecutor executor)
 {
     Contract.Requires(executor != null);
 }
コード例 #9
0
 void IServer.Start(IIpcOperationExecutor executor)
 {
     Contract.Requires(executor != null);
     StartFn(executor);
 }
コード例 #10
0
        /// <summary>
        /// 1. deserializes an <see cref="IIpcOperation"/> from a given <paramref name="stream"/>;
        /// 2. executes the operation (via <paramref name="executor"/>);
        /// 3. serializes and sends back the result via <paramref name="stream"/>.
        ///
        /// If executing the operation (via <paramref name="executor"/>) fails, the <see cref="IIpcResult.ExitCode"/>
        /// of the result is <see cref="IpcResultStatus.ExecutionError"/>
        /// </summary>
        internal static async Task <IIpcResult> ReceiveOperationAndExecuteLocallyAsync(Stream stream, IIpcOperationExecutor executor, CancellationToken token)
        {
            IIpcOperation operation = await IpcOperation.DeserializeAsync(stream, token);

            IIpcResult result = await HandleExceptionsAsync(IpcResultStatus.ExecutionError, () => executor.ExecuteAsync(operation));

            if (operation.ShouldWaitForServerAck)
            {
                await IpcResult.SerializeAsync(stream, result, token);
            }

            return(result);
        }