示例#1
0
文件: TcpPeer.cs 项目: ww-it/Raft.Net
 void SetupSprot()
 {
     _sprot1 = new cSprot1Parser();
     _sprot1.UseBigEndian = true;
     _sprot1.DestroySelf  = this.Dispose;
     _sprot1.packetParser = this.packetParser;
     //_sprot1.MessageQueue = _tcpServerClient.__IncomingDataBuffer;
     _sprot1.MaxPayLoad = 50000000; //this will be an approximate limitation for one command
     _sprot1.DeviceShouldSendAuthorisationBytesBeforeProceedCodec = false;
     _sprot1.ToSendToParserAuthenticationBytes = false;
 }
示例#2
0
文件: TcpPeer.cs 项目: ww-it/Raft.Net
        /// <summary>
        ///
        /// </summary>
        /// <param name="DontRemoveFromSpider"></param>
        /// <param name="calledFromDispose"></param>
        public void Dispose(bool DontRemoveFromSpider, bool calledFromDispose = false)
        {
            if (System.Threading.Interlocked.CompareExchange(ref disposed, 1, 0) != 0)
            {
                return;
            }

            string endpoint = null;

            try
            {
                endpoint = this.EndPointSID;
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (stream != null)
                {
                    stream.Dispose();
                    stream = null;
                }
            }
            catch (Exception)
            {}
            try
            {
                if (_client != null)
                {
                    (_client as IDisposable).Dispose();
                    _client = null;
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (_sprot1 != null)
                {
                    _sprot1.MessageQueue.Clear();
                    _sprot1 = null;
                }
            }
            catch (Exception)
            { }

            //trn.log.Log(new WarningLogEntry()
            //{
            //    LogType = WarningLogEntry.eLogType.DEBUG,
            //    //Description = $"{trn.port}> try connect {el.Host}:{el.Port} - {el.InternalNodeSID}"
            //    Description = $"{trn.port}> disposing {(Handshake == null ? "unknown" : Handshake.NodeListeningPort.ToString())} {(DontRemoveFromSpider ? " SPIDER NO REMOVE" : "") }"
            //});

            if (!DontRemoveFromSpider && endpoint != null)
            {
                trn.spider.RemovePeerFromClusterEndPoints(endpoint);
            }



            //-------------  Last line
            if (!calledFromDispose)
            {
                Dispose();
            }
        }