title: c# SslStream.EndRead return zero bytes
body: <p>My server program, deploy on many product environment run  well, buy on one of machine which doesn't run as we expect.</p>
  
  <p>On this machine , when we call SslStream.BeginRead,  then when SslStream.EndRead Called with 0 return,  if we don't close the stream, and call the SslStream again, there is an exception throwed。</p>
  
  <pre><code>private void Read()
      {
          try
          {
              if (this._IsClosed)
              {
                  return;
              }
              this._Stream.BeginRead(this._Buffer, 0,     BufferManager.Default.OutterReadBufferSize, this.EndRead, null);
          }
          catch (Exception ex)
          {
              _Logger.WarnFormat("Begin Read, session:{0}, {1}", this._Id, ex);
              this.Close();
          }
      }
  
  
  
  
  
  private void EndReadTaskAction(object ar)
      {
          try
          {
              int len = this._Stream.EndRead((IAsyncResult)ar);
              int used = 0;
              if (len &lt;= 0)
              {
                  _Logger.WarnFormat("EndReadTaskAction len less or equal zero, len={0}, session={1}", len, _Id);
                  this.Close();
                  return;
              }
  
              if (this._HasPartialPacket)
              {
                  if (this._PartialReadedLenth &lt; PacketConstants.HeadLength)
                  {
                      int needToRead = PacketConstants.HeadLength - this._PartialReadedLenth;
                      if (needToRead &gt; len)
                      {
                          Buffer.BlockCopy(this._Buffer, used, this._Buffer, GetCurrentPartialReadIndex(), len);
                          this._PartialReadedLenth += len;
                          Read();
                          return;
                      }
                      Buffer.BlockCopy(this._Buffer, used, this._Buffer, GetCurrentPartialReadIndex(), needToRead);
                      len -= needToRead;
                      used += needToRead;
                      this._PartialReadedLenth += needToRead;
                  }
                  int packetLength = PacketHelper.GetPacketLength(this._Buffer, this._PartialReadIndex);
                  int howMuchNeedToRead = packetLength - this._PartialReadedLenth;
                  if (howMuchNeedToRead &gt; len)
                  {
                      Buffer.BlockCopy(this._Buffer, used, this._Buffer, GetCurrentPartialReadIndex(), len);
                      this._PartialReadedLenth += len;
                      Read();
                      return;
                  }
                  Buffer.BlockCopy(this._Buffer, used, this._Buffer, GetCurrentPartialReadIndex(), howMuchNeedToRead);
                  ProcessPackage(this._Buffer, this._PartialReadIndex, packetLength);
                  len -= howMuchNeedToRead;
                  used += howMuchNeedToRead;
              }
              this._HasPartialPacket = false;
              this._PartialReadedLenth = 0;
              while (true)
              {
                  if (len &lt;= 0)
                  {
                      break;
                  }
  
                  if (len &lt; PacketConstants.HeadLength)
                  {
                      Buffer.BlockCopy(this._Buffer, used, this._Buffer, this._PartialReadIndex, len);
                      this._PartialReadedLenth = len;
                      this._HasPartialPacket = true;
                      break;
                  }
                  int packetLength = PacketHelper.GetPacketLength(this._Buffer, used);
                  if (len &lt; packetLength)
                  {
                      Buffer.BlockCopy(this._Buffer, used, this._Buffer, this._PartialReadIndex, len);
                      this._PartialReadedLenth = len;
                      this._HasPartialPacket = true;
                      break;
                  }
                  ProcessPackage(this._Buffer, used, packetLength);
                  used += packetLength;
                  len -= packetLength;
              }
              if (_isBeginRead)
              {
                  Read();
              }
          }
          catch (Exception ex)
          {
              _Logger.WarnFormat("End read, session:{0}, {1}", this._Id, ex);
              this.Close();
          }
      }
  </code></pre>