2016-07-22 71 views
0

我的服務器程序,部署在很多產品環境上運行良好,在我們所期望的不運行的機器上購買。c#SslStream.EndRead返回零字節

在這個機器上,當我們調用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(); 
     } 
    } 

回答

0

您在部署的服務器上表示您沒有任何問題,並且在新計算機中出現問題,請檢查所有dll的include和它的依賴關係,.net框架運行時。

希望它可以幫助..

+0

的DLL和它的依賴都good.when我從客戶端readed第一個數據包,然後不從流中讀取,登錄操作完成後,併發送登錄信息給客戶。經過上述操作,然後開始閱讀,並且正常運行。購買這個黑客看起來很直接 –