Esempio n. 1
0
        public void RPC_Bidirectional_Nested()
        {
            ipcMaster = new RpcBuffer(ipcName, async(msgId, payload) =>
            {
                // Ask slave to multiply the two bytes
                return((await ipcMaster.RemoteRequestAsync(new byte[] { 3, 3 }).ConfigureAwait(false)).Data);
            });
            ipcSlave = new RpcBuffer(ipcName, (msgId, payload) =>
            {
                return(new byte[] { (byte)(payload[0] * payload[1]) });
            });

            // Send request to master from slave
            var result = ipcSlave.RemoteRequest(null, 500);

            Assert.IsTrue(result.Success);
            Assert.AreEqual((3 * 3), result.Data[0]);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            long completed = 0;
            long count     = 0;

            byte[][] dataList;
            int      loopCount      = 2000;
            int      bufSize        = 1024 * 500;
            int      bufferCapacity = bufSize + 64; // buf size + enough room for protocol header
            int      threadCount    = 1;
            int      dataListCount  = 256;

            // Generate random data to be written
            Random random = new Random();

            dataList = new byte[dataListCount][];
            for (var j = 0; j < dataListCount; j++)
            {
                var data = new byte[bufSize];
                random.NextBytes(data);
                dataList[j] = data;
            }

            Console.WriteLine($"Thread count: {threadCount}");
            Console.WriteLine($"Buffer size: {bufferCapacity}");
            Console.WriteLine($"Message size: {bufSize}");

            Console.WriteLine("Running...");

            Stopwatch watch = Stopwatch.StartNew();

            for (var i = 0; i < threadCount; i++)
            {
                new Task(async() =>
                {
                    RpcBuffer ipcMaster = null;
                    RpcBuffer ipcSlave  = null;
                    var name            = $"MasterSlaveTest{Guid.NewGuid()}";
                    ipcMaster           = new RpcBuffer(name, bufferCapacity: bufferCapacity);
                    ipcSlave            = new RpcBuffer(name, (msgId, payload) =>
                    {
                        Interlocked.Increment(ref count);
                        return((byte[])null);
                        //return new byte[] { (byte)(payload[0] * payload[1]) };
                    });
                    var rnd       = new Random();
                    var watchLine = Stopwatch.StartNew();
                    for (var j = 0; j < loopCount; j++)
                    {
                        var result = await ipcMaster.RemoteRequestAsync(dataList[rnd.Next(0, dataList.Length)]);
                        if (!result.Success)
                        {
                            Console.WriteLine("Failed");
                            return;
                        }
                    }
                    Interlocked.Increment(ref completed);
                }).Start();
            }

            while (Interlocked.Read(ref completed) < threadCount)
            {
                Thread.Sleep(0);
            }

            watch.Stop();
            Console.WriteLine($"{count} in {watch.Elapsed}, {(int)(count / watch.Elapsed.TotalSeconds)} requests / sec");

            Console.ReadLine();
        }