Connect() публичный Метод

public Connect ( Uri adress ) : Task
adress System.Uri
Результат Task
Пример #1
0
        public static async Task ClientTcp()
        {
            RioTcpClientPool l = new RioTcpClientPool(new RioFixedBufferPool(Connections, Transfer), new RioFixedBufferPool(Connections, Transfer), (uint)Connections);
            int totalBytesRecived = 0;
            int currentRecived = 0;
            TaskCompletionSource<object> tcs;

            for (int i = 0; i < Iterations; i++)
            {
                var s = await l.Connect(new Uri(Target));

                if (Pattern == "PushPull")
                {
                    while (totalBytesRecived < Transfer)
                    {
                        tcs = new TaskCompletionSource<object>();
                        s.WriteFixed(new byte[PushBytes]);
                        s.OnIncommingSegment = seg =>
                        {
                            totalBytesRecived += seg.CurrentContentLength;
                            currentRecived += seg.CurrentContentLength;
                            if (currentRecived >= PullBytes)
                                tcs.SetResult(null);
                        };
                        await tcs.Task;
                    }
                }
                else if (Pattern == "Push")
                    s.WriteFixed(new byte[Transfer]);
                else if (Pattern == "Pull")
                {
                    tcs = new TaskCompletionSource<object>();

                    s.OnIncommingSegment = seg =>
                    {
                        totalBytesRecived += seg.CurrentContentLength;
                        if (totalBytesRecived >= Transfer)
                            tcs.SetResult(null);
                    };
                    await tcs.Task;
                }
                else if (Pattern == "Duplex")
                {
                    tcs = new TaskCompletionSource<object>();
                    s.WriteFixed(new byte[Transfer / 2]);
                    s.OnIncommingSegment = seg =>
                    {
                        totalBytesRecived += seg.CurrentContentLength;
                        if (totalBytesRecived >= Transfer / 2)
                            tcs.SetResult(null);
                    };
                }
            }

        }