当前位置: 首页>>代码示例>>C#>>正文


C# ITcpConnection.EnqueueSend方法代码示例

本文整理汇总了C#中ITcpConnection.EnqueueSend方法的典型用法代码示例。如果您正苦于以下问题:C# ITcpConnection.EnqueueSend方法的具体用法?C# ITcpConnection.EnqueueSend怎么用?C# ITcpConnection.EnqueueSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITcpConnection的用法示例。


在下文中一共展示了ITcpConnection.EnqueueSend方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendRandomData

        private void SendRandomData(ITcpConnection tcpConnection, bool small)
        {
            var rnd = new Random ();
            WaitCallback callBack = state =>
            {
                lock (tcpConnection) // to make sure ordered data generation -- even if we internally lock in enqueue
                    // the better test would be to generate consistent packages and verify them without this lock, but
                    // due to internal lock this lock just reduces probability of our problems not eliminating them
                {
                    var outData = new List<ArraySegment<byte>>();
                    var sent = _totalSent[tcpConnection];
                    var index = (int) (sent%_data.Length);

                    int size = (4 + ((!small && rnd.Next(2) == 0) ? _data.Length/2 + rnd.Next(_data.Length/2) : rnd.Next(32)))/4
                               *4;
                    if (index + size <= _data.Length)
                    {
                        outData.Add(new ArraySegment<byte>(_data, index, size));
                    }
                    else
                    {
                        outData.Add(new ArraySegment<byte>(_data, index, _data.Length - index));
                        outData.Add(new ArraySegment<byte>(_data, 0, size - _data.Length + index));
                    }
                    _totalSent[tcpConnection] += size;
                    Interlocked.Add(ref _sent, size);
                    tcpConnection.EnqueueSend(outData);
                }
            };

            if (rnd.Next (3) != 0) {
                small = true;
                var loopCount = rnd.Next(100);
                var nextRnd = 	 rnd.Next (4);
                for (var k = 0; k < 10; k++)
                    ThreadPool.QueueUserWorkItem (v =>
                    {
                        long h = 1;
                        // random cpu busy delay
                        for (long i = 0; i < loopCount; i++)
                            h = h + i;
                    // randon cpu free delay
                        callBack (null);
                        if (!small && nextRnd == 0) {
                            //Thread.Sleep (rnd.Next (5));
                            ThreadPool.QueueUserWorkItem (callBack);
                        }
                    }
                    );
            }
            else
            {
                callBack (null);
            //				callBack (null);
            //				callBack (null);
            }
        }
开发者ID:ysw,项目名称:mono-socket-problem,代码行数:57,代码来源:test_random_bidirectional_transfer.cs

示例2: SendRandomData

        private void SendRandomData(ITcpConnection tcpConnection, bool small)
        {
            var rnd = new Random ();
            WaitCallback callBack = state =>
            {

                var outData = new List<ArraySegment<byte>> ();
                int index = 0;

                int size = 1 + ((!small && rnd.Next (2) == 0) ? _data.Length/2 + rnd.Next (_data.Length/2) : rnd.Next (32));
                int totalSize = 0;
                outData.Add (new ArraySegment<byte> (_data, index, size));
                totalSize += size;
                Interlocked.Add (ref _sent, size);
                _totalSent [tcpConnection] += totalSize;
                tcpConnection.EnqueueSend (outData);
            };

            if (rnd.Next (5) != 0) {
                small = true;
                var loopCount = rnd.Next(10000);
                var nextRnd = 	 rnd.Next (4);
                for (var k = 0; k < 10; k++)
                    ThreadPool.QueueUserWorkItem (v =>
                    {
                        long h = 1;
                        // random cpu busy delay
                        for (long i = 0; i < loopCount; i++)
                            h = h + i;
                    // randon cpu free delay
                        callBack (null);
                        if (!small && nextRnd == 0) {
                            //Thread.Sleep (rnd.Next (5));
                            ThreadPool.QueueUserWorkItem (callBack);
                        }
                    }
                    );
            }
            else
            {
                callBack (null);
            //				callBack (null);
            //				callBack (null);
            }
        }
开发者ID:kpyatkivskyy,项目名称:mono-socket-problem,代码行数:45,代码来源:test_random_bidirectional_transfer.cs

示例3: OnDataReceived

 private void OnDataReceived(ITcpConnection conn, IEnumerable<ArraySegment<byte>> data)
 {
     conn.EnqueueSend(data);
     conn.ReceiveAsync(OnDataReceived);
 }
开发者ID:jen20,项目名称:tcp-servers-talk,代码行数:5,代码来源:BasicEchoServer.cs


注:本文中的ITcpConnection.EnqueueSend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。