private static void ConnectionCreatedCallback(object request, object state) { GlobalLog.Enter("ConnectAndHandshakeAsyncResult#" + ValidationHelper.HashString(request) + "::ConnectionCreatedCallback"); ConnectAndHandshakeAsyncResult ConnectAndHandshakeAsyncResult = (ConnectAndHandshakeAsyncResult)request; if (state is Exception) { ConnectAndHandshakeAsyncResult.InvokeCallback((Exception)state); return; } SmtpPooledStream pooledStream = (SmtpPooledStream)(PooledStream)state; try { while (pooledStream.creds != null && pooledStream.creds != ConnectAndHandshakeAsyncResult.connection.credentials) { GlobalLog.Print("ConnectAndHandshakeAsyncResult#" + ValidationHelper.HashString(request) + "::Connect pooledStream has wrong creds " + ValidationHelper.HashString(pooledStream)); ConnectAndHandshakeAsyncResult.connection.connectionPool.PutConnection(pooledStream, pooledStream.Owner, ConnectAndHandshakeAsyncResult.connection.Timeout, false); pooledStream = (SmtpPooledStream)ConnectAndHandshakeAsyncResult.connection.connectionPool.GetConnection((object)ConnectAndHandshakeAsyncResult, ConnectAndHandshakeAsyncResult.m_ConnectionCreatedCallback, ConnectAndHandshakeAsyncResult.connection.Timeout); if (pooledStream == null) { GlobalLog.Leave("ConnectAndHandshakeAsyncResult#" + ValidationHelper.HashString(request) + "::Connect returning asynchronously"); return; } } if (Logging.On) { Logging.Associate(Logging.Web, ConnectAndHandshakeAsyncResult.connection, pooledStream); } pooledStream.Owner = ConnectAndHandshakeAsyncResult.connection; //needs to be updated for gc reasons pooledStream.creds = ConnectAndHandshakeAsyncResult.connection.credentials; lock (ConnectAndHandshakeAsyncResult.connection) { //if we were cancelled while getting the connection, we should close and return if (ConnectAndHandshakeAsyncResult.connection.isClosed) { ConnectAndHandshakeAsyncResult.connection.connectionPool.PutConnection(pooledStream, pooledStream.Owner, ConnectAndHandshakeAsyncResult.connection.Timeout, false); GlobalLog.Print("ConnectAndHandshakeAsyncResult#" + ValidationHelper.HashString(request) + "::ConnectionCreatedCallback Connect was aborted " + ValidationHelper.HashString(pooledStream)); ConnectAndHandshakeAsyncResult.InvokeCallback(null); return; } ConnectAndHandshakeAsyncResult.connection.pooledStream = pooledStream; } ConnectAndHandshakeAsyncResult.Handshake(); } catch (Exception e) { ConnectAndHandshakeAsyncResult.InvokeCallback(e); } GlobalLog.Leave("ConnectAndHandshakeAsyncResult#" + ValidationHelper.HashString(request) + "::ConnectionCreatedCallback pooledStream#" + ValidationHelper.HashString(pooledStream)); }
private static void ConnectionCreatedCallback(object request, object state) { if (GlobalLog.IsEnabled) { GlobalLog.Enter("ConnectAndHandshakeAsyncResult#" + LoggingHash.HashString(request) + "::ConnectionCreatedCallback"); } ConnectAndHandshakeAsyncResult ConnectAndHandshakeAsyncResult = (ConnectAndHandshakeAsyncResult)request; if (state is Exception) { ConnectAndHandshakeAsyncResult.InvokeCallback((Exception)state); return; } try { lock (ConnectAndHandshakeAsyncResult._connection) { //if we were cancelled while getting the connection, we should close and return if (ConnectAndHandshakeAsyncResult._connection._isClosed) { ConnectAndHandshakeAsyncResult._connection.ReleaseConnection(); if (GlobalLog.IsEnabled) { GlobalLog.Print("ConnectAndHandshakeAsyncResult#" + LoggingHash.HashString(request) + "::ConnectionCreatedCallback Connect was aborted "); } ConnectAndHandshakeAsyncResult.InvokeCallback(null); return; } } ConnectAndHandshakeAsyncResult.Handshake(); } catch (Exception e) { ConnectAndHandshakeAsyncResult.InvokeCallback(e); } if (GlobalLog.IsEnabled) { GlobalLog.Leave("ConnectAndHandshakeAsyncResult#" + LoggingHash.HashString(request) + "::ConnectionCreatedCallback"); } }
private static void ConnectionCreatedCallback(object request, object state) { if (NetEventSource.IsEnabled) { NetEventSource.Enter(null, request); } ConnectAndHandshakeAsyncResult ConnectAndHandshakeAsyncResult = (ConnectAndHandshakeAsyncResult)request; if (state is Exception) { ConnectAndHandshakeAsyncResult.InvokeCallback((Exception)state); return; } try { lock (ConnectAndHandshakeAsyncResult._connection) { //if we were cancelled while getting the connection, we should close and return if (ConnectAndHandshakeAsyncResult._connection._isClosed) { ConnectAndHandshakeAsyncResult._connection.ReleaseConnection(); if (NetEventSource.IsEnabled) { NetEventSource.Info(null, $"Connect was aborted: {request}"); } ConnectAndHandshakeAsyncResult.InvokeCallback(null); return; } } ConnectAndHandshakeAsyncResult.Handshake(); } catch (Exception e) { ConnectAndHandshakeAsyncResult.InvokeCallback(e); } if (NetEventSource.IsEnabled) { NetEventSource.Exit(null, request); } }
private static void InitializeConnectionCallback(IAsyncResult result) { if (!result.CompletedSynchronously) { ConnectAndHandshakeAsyncResult thisPtr = (ConnectAndHandshakeAsyncResult)result.AsyncState; try { thisPtr._connection.EndInitializeConnection(result); if (NetEventSource.IsEnabled) { NetEventSource.Info(null, $"Connect returned {thisPtr}"); } thisPtr.Handshake(); } catch (Exception e) { thisPtr.InvokeCallback(e); } } }
private static void InitializeConnectionCallback(IAsyncResult result) { if (!result.CompletedSynchronously) { ConnectAndHandshakeAsyncResult thisPtr = (ConnectAndHandshakeAsyncResult)result.AsyncState; thisPtr._connection.EndInitializeConnection(result); if (GlobalLog.IsEnabled) { GlobalLog.Print("ConnectAndHandshakeAsyncResult#" + LoggingHash.HashString(thisPtr) + "::Connect returned" + LoggingHash.HashString(thisPtr)); } try { thisPtr.Handshake(); } catch (Exception e) { thisPtr.InvokeCallback(e); } } }