/// <summary> /// Stores RelayMessageInfo to byte[]. /// </summary> /// <returns>Returns RelayMessageInfo as byte[] data.</returns> public byte[] ToByte() { XmlTable retVal = new XmlTable("RelayMessageInfo"); if (!string.IsNullOrEmpty(m_EnvelopeID)) { retVal.Add("EnvelopeID", m_EnvelopeID); } retVal.Add("Sender", m_Sender); retVal.Add("Recipient", m_Recipient); if (!string.IsNullOrEmpty(m_OriginalRecipient)) { retVal.Add("OriginalRecipient", m_OriginalRecipient); } if (m_DSN_Notify != SMTP_DSN_Notify.NotSpecified) { retVal.Add("DSN-Notify", m_DSN_Notify.ToString()); } if (m_DSN_Ret != SMTP_DSN_Ret.NotSpecified) { retVal.Add("DSN-RET", m_DSN_Ret.ToString()); } retVal.Add("Date", m_Date.ToString("r")); retVal.Add("DelayedDeliveryNotifySent", m_DelayedDeliveryNotifySent.ToString()); if (m_pHostEndPoint != null) { retVal.Add("HostEndPoint", m_pHostEndPoint.ToString()); } else { retVal.Add("HostEndPoint", ""); } return(retVal.ToByteData()); }
// Main listener thread. Starts an indefinite loop listening for // new socket clients. As Each client comes in, it is handed off // to OnClientConnect asynchronously on its own ThreadPool thread. private void StartListening() { Log.Info("Inside Listener Thread."); _listener = CreateListenerSocket(); try { _listener.Bind(HostEndPoint); _listener.Listen(PENDING_CONNECTION_QUEUE_SIZE); if (Log.IsInfoEnabled) { Log.Info("Socket Listener Started Listening on " + HostEndPoint.ToString()); } // This loops indefinitely listening for client connections. while (_isRunning) { // Set event to nonsignaled state. _clientConnected.Reset(); Log.Info("Ready to Accept Incoming Connection."); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. _listener.BeginAccept(new AsyncCallback(AcceptIncomingConnection), _listener); if (Log.IsInfoEnabled) { Log.Info("Waiting For a Connection..."); } // Wait for the connection to be made before continuing. // But do so in a non-blocking manner. while (true) { if (_clientConnected.WaitOne(1000, false)) { Log.Info("Breaking out of the infinite loop because we have a new connection."); break; } if (!_isRunning) { Log.Warn("Breaking out of the infinite loop because the server is stopping."); break; } } } Log.Info("Exiting Listener Thread Gracefully."); } catch (Exception e) { //TODO: Consider starting up again. Log.Error("Exception thrown in StartListening() thread. Server is shutting down.", e); } }