Exemplo n.º 1
0
        /// <summary>
        /// Resolving multiple host IPv4 and IPv6 addresses.
        /// </summary>
        /// <param name="hostNames">Host names to resolve.</param>
        /// <param name="resolveAny">If true, as long as one host name is resolved, no error returned.</param>
        /// <returns>Returns host entries.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and and this method is accessed.</exception>
        /// <exception cref="ArgumentNullException">Is raised when <b>hostNames</b> is null reference.</exception>
        /// <exception cref="DNS_ClientException">Is raised when DNS server returns error.</exception>
        /// <exception cref="IOException">Is raised when IO reletaed error happens.</exception>
        public HostEntry[] GetHostsAddresses(string[] hostNames,bool resolveAny)
        {
            if(m_IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(hostNames == null){
                throw new ArgumentNullException("hostNames");
            }

            ManualResetEvent wait = new ManualResetEvent(false);
            using(Dns_Client.GetHostsAddressesAsyncOP op = new Dns_Client.GetHostsAddressesAsyncOP(hostNames,resolveAny)){
                op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetHostsAddressesAsyncOP> e1){
                    wait.Set();
                };
                if(!this.GetHostsAddressesAsync(op)){
                    wait.Set();
                }
                wait.WaitOne();
                wait.Close();

                if(op.Error != null){
                    throw op.Error;
                }
                else{
                    return op.HostEntries;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Start processing relay message.
        /// </summary>
        /// <param name="state">User data.</param>
        internal void Start(object state)
        {
            try{ 
                if(m_pServer.Logger != null){
                    m_pSmtpClient.Logger = new Logger();
                    m_pSmtpClient.Logger.WriteLog += new EventHandler<WriteLogEventArgs>(SmtpClient_WriteLog);
                }

                LogText("Starting to relay message '" + m_pRelayItem.MessageID + "' from '" + m_pRelayItem.From + "' to '" + m_pRelayItem.To + "'.");

                // Resolve email target hosts.               
                if(m_RelayMode == Relay_Mode.Dns){
                    Dns_Client.GetEmailHostsAsyncOP op = new Dns_Client.GetEmailHostsAsyncOP(m_pRelayItem.To);
                    op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetEmailHostsAsyncOP> e1){
                        EmailHostsResolveCompleted(m_pRelayItem.To,op);
                    };
                    if(!m_pServer.DnsClient.GetEmailHostsAsync(op)){
                        EmailHostsResolveCompleted(m_pRelayItem.To,op);
                    }
                }
                // Resolve smart hosts IP addresses.
                else if(m_RelayMode == Relay_Mode.SmartHost){
                    string[] smartHosts = new string[m_pSmartHosts.Length];
                    for(int i=0;i<m_pSmartHosts.Length;i++){
                        smartHosts[i] = m_pSmartHosts[i].Host;
                    }

                    Dns_Client.GetHostsAddressesAsyncOP op = new Dns_Client.GetHostsAddressesAsyncOP(smartHosts);
                    op.CompletedAsync += delegate(object s1,EventArgs<Dns_Client.GetHostsAddressesAsyncOP> e1){
                        SmartHostsResolveCompleted(op);
                    };
                    if(!m_pServer.DnsClient.GetHostsAddressesAsync(op)){
                        SmartHostsResolveCompleted(op);
                    }
                } 
            }
            catch(Exception x){
                Dispose(x);
            }
        }