public override IEnumerator DoAsync()
 {
     ReadStream = File.OpenRead(this.SourcePath + this.FilePath);
     ByteDatas  = new byte[ReadStream.Length];
     ReadStream.BeginRead(ByteDatas, 0, (int)ReadStream.Length, new AsyncCallback(OnReadStreamCallback), this);
     yield break;
 }
Exemplo n.º 2
0
        private void StartReading(HostInfo hostInfo)
        {
            // Initialize comunication
            CreateAndConnect(hostInfo);


            // Start receiving
            ReadContext readContext = new ReadContext(4 * 1024, this.connectionVersion);

            ReadStream.BeginRead(readContext.Data, 0, readContext.Data.Length, new AsyncCallback(ReadCallback), readContext);
        }
Exemplo n.º 3
0
        private void ReadCallback(IAsyncResult asyncResult)
        {
            try
            {
                ReadContext readContext = (ReadContext)asyncResult.AsyncState;
                byte[]      rawData     = readContext.Data;

                int bytesReceived = 0;
                try
                {
                    bytesReceived = ReadStream.EndRead(asyncResult);
                }
                catch (Exception)
                {
                    bytesReceived = 0;
                }

                if (bytesReceived == 0)
                {
                    // Read as failed (bytes received == 0 or exception in EndRead)
                    ReadFailed(readContext);
                    return;
                }

                MessageAccumulator msgAcc = readContext.Accumulator;
                ProcessReceivedData(ref msgAcc, rawData, bytesReceived);
                readContext.Accumulator = msgAcc;


                //continue to read if it's not closed.
                lock (this)
                {
                    if (closed)
                    {
                        return;
                    }
                }
                ReadStream.BeginRead(readContext.Data, 0, readContext.Data.Length, new AsyncCallback(ReadCallback), readContext);
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }
Exemplo n.º 4
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     return(ReadStream.BeginRead(buffer, offset, count, callback, state));
 }