2016-07-22 13 views
0

私のサーバープログラムは、多くの製品環境でうまく動作し、期待したとおりに動作しないマシンの1台で購入します。このマシンでc#SslStream.EndRead return zero bytes

、我々はSslStream.BeginReadを呼び出すときに我々は、ストリームを閉じて、再度SslStreamを呼び出さない場合は、SslStream.EndReadは0リターンで呼び出されたときに、throwed例外がある。

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のインクルードとその依存関係、.netフレームワークの実行時間を確認してください。

は、DLLのとその依存関係はすべて、完全なログイン操作の後、ストリームから読み込まれ、ログイン情報を送信しない、私はクライアントからの最初のパケットをreaded good.whenている

+0

...それがお役に立てば幸いクライアントに送信します。上記の操作の後、読み取りを開始し、正常に実行されます。このハックを購入すると、奇妙に見えます –