Add() public method

public Add ( int value ) : void
value int
return void
Beispiel #1
0
        public override async Task <int> ReadAsync(byte[] buf, int offset, int length, CancellationToken cancel_token)
        {
            if (closedCancelSource.IsCancellationRequested)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            var len = await WaitOrCancelTask(ct => ReadStream.ReadAsync(buf, offset, length, ct), ReadTimeout, cancel_token).ConfigureAwait(false);

            readBytesCounter.Add(len);
            return(len);
        }
Beispiel #2
0
        public override async Task <int> ReadAsync(byte[] buf, int offset, int length, CancellationToken cancel_token)
        {
            if (closedCancelSource.IsCancellationRequested)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            CheckReadException();
            var len = await readBuffer.ReadAsync(buf, offset, length, cancel_token).ConfigureAwait(false);

            CheckReadException();
            readBytesCounter.Add(len);
            return(len);
        }
 private void ProcessSend()
 {
     if (sendResult != null && sendResult.IsCompleted)
     {
         try {
             OutputStream.EndWrite(sendResult);
             sendBytesCounter.Add((int)sendResult.AsyncState);
         }
         catch (ObjectDisposedException) {
         }
         catch (IOException) {
             OnError();
         }
         sendResult = null;
     }
     if (!HasError && sendResult == null && sendStream.Length > 0)
     {
         var buf = sendStream.ToArray();
         sendStream.SetLength(0);
         sendStream.Position = 0;
         try {
             sendResult = OutputStream.BeginWrite(buf, 0, buf.Length, null, buf.Length);
         }
         catch (ObjectDisposedException) {
         }
         catch (IOException) {
             OnError();
         }
     }
 }
Beispiel #4
0
 private void Flush()
 {
     foreach (var content in builder.ToContents())
     {
         this.BaseSink.OnContent(content);
         packetRateCounter.Add(1);
     }
     builder.Clear();
 }
        public override int Read(byte[] buffer, int offset, int count)
        {
            var result = BaseStream.Read(buffer, offset, count);

            if (result > 0)
            {
                readCounter.Add(result);
            }
            return(result);
        }
Beispiel #6
0
        private void Flush()
        {
            var content = builder.ToContent();

            if (content != null)
            {
                this.BaseSink.OnContent(content);
                packetRateCounter.Add(1);
            }
            builder.Clear();
        }
Beispiel #7
0
 private void OnReceive(IAsyncResult ar)
 {
     lock (recvLock) {
         try {
             int bytes = inputStream.EndRead(ar);
             if (bytes > 0)
             {
                 recvBytesCounter.Add(bytes);
                 recvStream.Seek(0, SeekOrigin.End);
                 recvStream.Write(recvBuffer, 0, bytes);
                 recvStream.Seek(0, SeekOrigin.Begin);
             }
             else
             {
                 if (!closing)
                 {
                     recvException = new EndOfStreamException();
                 }
             }
         }
         catch (ObjectDisposedException e) {
             if (!closing)
             {
                 recvException = e;
             }
         }
         catch (IOException e) {
             if (!closing)
             {
                 recvException = e;
             }
         }
         recvResult = null;
         recvEvent.Set();
         if (recvException == null && !closing)
         {
             try {
                 recvResult = inputStream.BeginRead(recvBuffer, 0, recvBuffer.Length, OnReceive, null);
                 if (recvTimeout >= 0)
                 {
                     ThreadPool.RegisterWaitForSingleObject(recvResult.AsyncWaitHandle, OnReceiveTimeout, recvResult, recvTimeout, true);
                 }
             }
             catch (ObjectDisposedException e) {
                 recvException = e;
                 recvEvent.Set();
             }
             catch (IOException e) {
                 recvException = e;
                 recvEvent.Set();
             }
         }
     }
 }
Beispiel #8
0
        public override async Task WriteAsync(byte[] buf, int offset, int length, CancellationToken cancel_token)
        {
            if (closedCancelSource.IsCancellationRequested)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            await WaitOrCancelTask(ct => WriteStream.WriteAsync(buf, offset, length, ct), WriteTimeout, cancel_token).ConfigureAwait(false);

            if (!closedCancelSource.IsCancellationRequested && !cancel_token.IsCancellationRequested)
            {
                writeBytesCounter.Add(length);
            }
        }
Beispiel #9
0
        public override async Task WriteAsync(byte[] buf, int offset, int length, CancellationToken cancel_token)
        {
            if (closedCancelSource.IsCancellationRequested)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            CheckWriteException();
            await writeBuffer.WriteAsync(buf, offset, length, cancel_token).ConfigureAwait(false);

            CheckWriteException();
            if (!closedCancelSource.IsCancellationRequested && !cancel_token.IsCancellationRequested)
            {
                writeBytesCounter.Add(length);
            }
        }
Beispiel #10
0
 private void OnSend(IAsyncResult ar)
 {
     lock (sendLock) {
         bool err = false;
         try {
             outputStream.EndWrite(ar);
             sendBytesCounter.Add(((SendState)ar.AsyncState).Length);
         }
         catch (ObjectDisposedException e) {
             err = true;
             if (!closing)
             {
                 sendException = e;
             }
         }
         catch (IOException e) {
             err = true;
             if (!closing)
             {
                 sendException = e;
             }
         }
         sendResult = null;
         if (sendException == null && !err && sendPackets.Count > 0)
         {
             var buf = sendPackets.Dequeue();
             try {
                 var state = new SendState(buf.Length);
                 sendResult = outputStream.BeginWrite(buf, 0, buf.Length, null, state);
                 ThreadPool.RegisterWaitForSingleObject(sendResult.AsyncWaitHandle, OnSendTimeout, sendResult, sendTimeout, true);
             }
             catch (ObjectDisposedException e) {
                 if (!closing)
                 {
                     sendException = e;
                 }
             }
             catch (IOException e) {
                 if (!closing)
                 {
                     sendException = e;
                 }
             }
         }
     }
 }
Beispiel #11
0
 protected void ProcessRecv()
 {
     if (inputStream == null)
     {
         return;
     }
     if (recvResult != null && recvResult.IsCompleted)
     {
         try {
             int bytes = inputStream.EndRead(recvResult);
             if (bytes > 0)
             {
                 recvBytesCounter.Add(bytes);
                 recvStream.Seek(0, SeekOrigin.End);
                 recvStream.Write(recvBuffer, 0, bytes);
                 recvStream.Seek(0, SeekOrigin.Begin);
                 RecvEvent.Set();
             }
             else if (bytes < 0)
             {
                 recvError = true;
             }
             else
             {
                 recvError = true;
             }
         }
         catch (ObjectDisposedException) {}
         catch (IOException) {
             recvError = true;
         }
         recvResult = null;
     }
     if (!recvError && !HasError && recvResult == null)
     {
         try {
             recvResult = inputStream.BeginRead(recvBuffer, 0, recvBuffer.Length, null, null);
         }
         catch (ObjectDisposedException) {
         }
         catch (IOException) {
             recvError = true;
         }
     }
 }
 private void ProcessRecv()
 {
     if (recvResult != null && recvResult.IsCompleted)
     {
         try {
             int bytes = InputStream.EndRead(recvResult);
             if (bytes > 0)
             {
                 recvBytesCounter.Add(bytes);
                 recvStream.Seek(0, SeekOrigin.End);
                 recvStream.Write(recvBuffer, 0, bytes);
                 recvStream.Seek(0, SeekOrigin.Begin);
             }
             else if (bytes < 0)
             {
                 OnError();
             }
         }
         catch (ObjectDisposedException) {}
         catch (IOException) {
             OnError();
         }
         recvResult = null;
     }
     if (!HasError && recvResult == null)
     {
         try {
             recvResult = InputStream.BeginRead(recvBuffer, 0, recvBuffer.Length, null, null);
         }
         catch (ObjectDisposedException) {
         }
         catch (IOException) {
             OnError();
         }
     }
 }
Beispiel #13
0
 public void OnContent(Content content)
 {
     this.Channel.Contents.Add(content);
     packetRateCounter.Add(1);
     this.LastContent = content;
 }
 public override void Write(byte[] buffer, int offset, int count)
 {
     BaseStream.Write(buffer, offset, count);
     writeCounter.Add(count);
 }