コード例 #1
0
 private void m_RemoveTimedOutCallBacks()
 {
     try
     {
         ArrayList timedOutCalledBack = null;
         lock (UploadList.SyncRoot)
         {
             try
             {
                 foreach (CClient Client in UploadList)
                 {
                     if ((Client.UploadState == Protocol.UploadState.WaitCallBack) &&
                         (Client.CallBackTimedOut))
                     {
                         if (timedOutCalledBack == null)
                         {
                             timedOutCalledBack = new ArrayList();
                         }
                         timedOutCalledBack.Add(Client);
                     }
                 }
             }
             catch (Exception e)
             {
                 Debug.WriteLine(e.ToString());
             }
         }
         if (timedOutCalledBack != null)
         {
             foreach (CClient CallBackClient in timedOutCalledBack)
             {
                 CallBackClient.OnDisconnect((byte)Protocol.ConnectionReason.CannotConnect);
             }
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
     }
 }
コード例 #2
0
ファイル: SourcesList.cs プロジェクト: biuken/eAnt
        public void Process()
        {
            //Search more sources in the connected server
//			if (((DateTime.Now-m_LastTCPSearch)>new TimeSpan(0,Protocol.ReaskClient,0))&&
//				(CKernel.Preferences.GetInt("MaxSourcesPerFile")>m_ArrayList.Count-5))
//			{
//				if ((CKernel.ServersList.ActiveServer!=null)&&(m_Element!=null)&&(m_Element.File!=null))
//				{
//					CKernel.ServersList.ActiveServer.RequestSources(m_Element.File.FileHash);
//					m_LastTCPSearch=DateTime.Now;
//					Debug.Write("Asking for file "+ m_Element.File.GetFileName() +"\n");
//				}
//			}
            float     aux_VelocidadDescarga   = 0;
            ushort    aux_nDownloadingClients = 0;
            ushort    aux_nUsableClients      = 0;
            float     factor;
            ArrayList timedOutCalledBack = null;

            lock (m_ArrayList.SyncRoot)
            {
                try
                {
                    foreach (CClient Client in m_ArrayList)
                    {
                        factor = 1.0F;
                        if (Client.DownloadState == Protocol.DownloadState.NoNeededParts)
                        {
                            factor = 2.0F;
                        }
                        else if ((Client.SoftwareID == (uint)Protocol.Client.mlDonkey) && (Client.DownloadTries > 0))
                        {
                            factor = 0.55F;
                        }
                        else if ((Client.QRDownload == 0) && (Client.DownloadTries > 0))
                        {
                            factor = 0.75F;
                        }

                        if ((DateTime.Now - Client.LastDownloadRequest > new TimeSpan(0, 0, (int)((float)Protocol.MinClientReask * factor) - 1, 0)) &&
                            (Client.DownloadState != Protocol.DownloadState.Connecting) &&
                            (Client.DownloadState != Protocol.DownloadState.Downloading) &&
                            (Client.DownloadState != Protocol.DownloadState.Connected) &&
                            (Client.DownloadState != Protocol.DownloadState.WaitCallBack))
                        {
                            if (!Client.AskingUDP)
                            {
                                Client.TryUDPDownload();
                            }
                            else
                            {
                                if (DateTime.Now - Client.LastDownloadRequest > new TimeSpan(0, 0, (int)((float)Protocol.MinClientReask * factor), 0))
                                {
                                    Client.TryDownload();
                                }
                            }
                        }

                        if ((Client.DownloadState == Protocol.DownloadState.Downloading))
                        {
                            aux_nDownloadingClients++;
                            Client.UpdateDownloadSpeed();
                            aux_VelocidadDescarga += Client.DownloadSpeed;
                        }

                        if ((Client.DownloadState == Protocol.DownloadState.WaitCallBack)
                            //||(Client.UploadState==Protocol.UploadState.WaitCallBack))
                            && (Client.CallBackTimedOut))
                        {
                            if (timedOutCalledBack == null)
                            {
                                timedOutCalledBack = new ArrayList();
                            }
                            timedOutCalledBack.Add(Client);
                        }

                        if ((Client.DownloadState != Protocol.DownloadState.None) &&
                            (Client.DownloadState != Protocol.DownloadState.NoNeededParts))
                        {
                            aux_nUsableClients++;
                        }
                    }
                }
                catch (InvalidOperationException e)
                {
                    //in some vary rare case the enumerating the sources collection can fail
                    //possible errors a can not create a socket or similar
                    //we catch this execption and continue since we will process sources again in 1 second
                    //if entering here is not rare then we must delete the sources with this error outside the loop
#if DEBUG
                    CLog.Log(Types.Constants.Log.Verbose, "Error enumerating sources collection in SourcesList.Process " + e.ToString());
#endif
                    Debug.WriteLine(e.ToString());
                }
            }

            // Disconnect may modify the sources list collection, so we disconnect outside the loop
            if (timedOutCalledBack != null)
            {
                foreach (CClient CallBackClient in timedOutCalledBack)
                {
                    CallBackClient.OnDisconnect((byte)Protocol.ConnectionReason.CannotConnect);
                }
            }

            m_PrevDownloadSpeed   = m_DownloadSpeed;
            m_DownloadSpeed       = aux_VelocidadDescarga;
            m_nDownloadingClients = aux_nDownloadingClients;
            m_nUsableClients      = aux_nUsableClients;
        }