Моя серверная программа, развернутая во многих продуктах, хорошо работает, покупайте на одном из компьютеров, который не работает так, как мы ожидаем.C# SslStream.EndRead return zero bytes
На этой машине, когда мы называем SslStream.BeginRead, а затем, когда SslStream.EndRead Вызывается с 0 возвращением, если мы не закрываем поток, а затем снова вызвать SslStream, есть исключение забросили.
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 <= 0)
{
_Logger.WarnFormat("EndReadTaskAction len less or equal zero, len={0}, session={1}", len, _Id);
this.Close();
return;
}
if (this._HasPartialPacket)
{
if (this._PartialReadedLenth < PacketConstants.HeadLength)
{
int needToRead = PacketConstants.HeadLength - this._PartialReadedLenth;
if (needToRead > 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 > 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 <= 0)
{
break;
}
if (len < 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 < 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();
}
}
Dll и его зависимости всех good.when I прочитанных первый пакет от клиента, то не читать из потока после операции входа в системе полной и отправить регистрационную информацию для клиента. После выполнения вышеуказанных операций начните читать, и он запускается нормально. Купить этот хак выглядит странно –