Exemplo n.º 1
0
 public System.Threading.Tasks.Task <int> Receive(byte[] buffer, int offset, int count)
 {
     return(System.Threading.Tasks.Task <int> .Run(() =>
     {
         int readCount = _Stream.Read(buffer, offset, count);
         AutoPowerRegulator r = new Regulus.Utility.AutoPowerRegulator(new PowerRegulator());
         while (readCount == 0)
         {
             r.Operate();
             readCount = _Stream.Read(buffer, offset, count);
         }
         return readCount;
     }));
 }
Exemplo n.º 2
0
        public IWaitableValue <int> Receive(byte[] buffer, int offset, int count)
        {
            var task = System.Threading.Tasks.Task <int> .Run(() =>
            {
                int readCount = 0;
                var r         = new Regulus.Utility.AutoPowerRegulator(new PowerRegulator());
                while (readCount == 0)
                {
                    r.Operate();
                    readCount = _Stream.Read(buffer, offset, count);
                }
                return(readCount);
            });

            return(task.ToWaitableValue());
        }
Exemplo n.º 3
0
        void IStage <Timestamp> .Update(Timestamp timestamp)
        {
            while (_SendTasks.Count > 0)
            {
                Task task = null;
                if (_SendTasks.TryDequeue(out task))
                {
                    for (int i = task.Offset; i < task.Count; i++)
                    {
                        _SendBytes.Add(task.Buffer[i]);
                    }
                    task.Done(task.Count);
                }
            }

            if (_SendBytes.Count > 0)
            {
                _Line.WriteTransmission(_SendBytes.ToArray());
                _SendBytes.Clear();
            }

            while (_Stream.Count > 0)
            {
                lock (_ReadTask)
                {
                    var handler = _ReadTask;
                    if (handler.Buffer != null)
                    {
                        var readCount = _Stream.Read(handler.Buffer, handler.Offset, handler.Count);
                        if (readCount > 0)
                        {
                            handler.Done(readCount);
                        }
                    }
                }
            }



            SocketMessage message;

            while ((message = _Line.Read()) != null)
            {
                _Timeout = 0;
                var package = message;

                var operation = (PeerOperation)package.GetOperation();
                if (operation == PeerOperation.Transmission)
                {
                    _Stream.Add(package);
                }
                else if (operation == PeerOperation.RequestDisconnect)
                {
                    DisconnectEvent();
                }
            }

            _Timeout += timestamp.DeltaTicks;
            if (_Timeout > Config.Timeout * Timestamp.OneSecondTicks)
            {
                DisconnectEvent();
            }
        }