/// <summary> /// Checks the timeout entrys for any that have expired. /// </summary> public void CheckTimeouts( ) { lock (List.SyncRoot) { if (List.Count == 0) { return; } for (int i = 0; i < List.Count; i++) { TimeoutEntry toe = List[i] as TimeoutEntry; if (toe == null) { continue; } if (toe.TimeoutTime < DateTime.Now) { m_Parent.ConnectionRequestTimedOut(toe.ServerIP, toe.ServerPort, toe.ConnectionRequestID); List.Remove(toe); return; } } } }
/// <summary> /// Returns whether or not a connection reauest exists based on its unique request ID. /// </summary> public bool EntryExists(string RequestID) { lock (List.SyncRoot) { for (int i = 0; i < List.Count; i++) { TimeoutEntry toe = List[i] as TimeoutEntry; if (toe == null) { continue; } if (toe.ConnectionRequestID == RequestID) { return(true); } } } return(false); }
/// <summary> /// Adds a connection into the timeout list /// </summary> public void AddConnectionEntry(string IP, int Port, int TimeoutSecs, string RequestID) { lock (List.SyncRoot) { //Remove any existing connection attempt to this IP/Port. if (EntryExists(IP, Port)) { RemoveConnectionEntry(IP, Port); } //Create the entry TimeoutEntry toe = new TimeoutEntry( ); toe.ServerIP = IP; toe.ServerPort = Port; toe.TimeoutTime = DateTime.Now.AddSeconds(TimeoutSecs); toe.ConnectionRequestID = RequestID; //Add to the list List.Add(toe); } }
/// <summary> /// Removes a connection from the timeout list /// </summary> public void RemoveConnectionEntry(string request_id) { lock (List.SyncRoot) { for (int i = 0; i < List.Count; i++) { TimeoutEntry toe = List[i] as TimeoutEntry; if (toe == null) { continue; } if (toe.ConnectionRequestID == request_id) { List.Remove(toe); return; } } } }
/// <summary> /// Removes a connection from the timeout list /// </summary> public void RemoveConnectionEntry(string IP, int Port) { lock (List.SyncRoot) { for (int i = 0; i < List.Count; i++) { TimeoutEntry toe = List[i] as TimeoutEntry; if (toe == null) { continue; } if ((toe.ServerIP == IP) && (toe.ServerPort == Port)) { List.Remove(toe); return; } } } }
/// <summary> /// Finds out whether a time out entry exists or not. /// </summary> public bool EntryExists(string IP, int Port) { lock (List.SyncRoot) { for (int i = 0; i < List.Count; i++) { TimeoutEntry toe = List[i] as TimeoutEntry; if (toe == null) { continue; } if ((toe.ServerIP == IP) && (toe.ServerPort == Port)) { return(true); } } } return(false); }