/// <summary> /// Default constructor. /// </summary> public RelayVariablesManager(Relay_Session relaySession,string errorText,Stream messageStream) { m_pRealySession = relaySession; m_ErrorText = errorText; m_pMessageStream = messageStream; try{ m_pMime = Mime.Parse(messageStream); } catch{ } }
/// <summary> /// Adds specified session to sessions collection. /// </summary> /// <param name="session">Session to add.</param> private void AddSession(Relay_Session session) { lock(m_pSessions){ m_pSessions.Add(session); } }
/// <summary> /// This loop sends queued messages. /// </summary> private void ProcessQueue() { while(m_Running){ try{ /* Get relay job from queue. Relay queue is with priority 1. Retry queue is with priority 2. This assures that retry attempt connections won't use all allowed connections. */ // There are no relay jobs available now or maximum allowed relay connections reached. // Just fall down 'while', sleep a little and try with next while loop. if(!(m_pRelayQueue.Count == 0 && m_pRelayRetryQueue.Count == 0) && m_pSessions.Count < m_MaxConnections){ lock(this){ string file = ""; // Relay job available, get it, because it's with higher priority. if(m_pRelayQueue.Count > 0){ file = m_pRelayQueue.Dequeue(); } // Relay retry job. else{ file = m_pRelayRetryQueue.Dequeue(); } try{ bool relay_retry = true; if(file.ToLower().IndexOf("retry") > -1){ relay_retry = false; } Relay_Session session = new Relay_Session(this,file,relay_retry); AddSession(session); session.Start(); } catch(IOException x){ // Just skip IO exceptions, they happen when incoming message storing hasn't // completed yet and relay engine tries to relay this message. string dummy = x.Message; } } } } catch(Exception x){ Error.DumpError(m_pVirtualServer.Name,x); } // Sleep, otherwise run loop takes 100% CPU. Thread.Sleep(10); } }
/// <summary> /// Removes specified session from sessions collection. /// </summary> /// <param name="session">Session to remove.</param> internal void RemoveSession(Relay_Session session) { lock(m_pSessions){ m_pSessions.Remove(session); } }