internal static SecurityStatus AcceptSecurityContext(SSPIInterface SecModule, ref SafeFreeCredentials credential, ref SafeDeleteContext context, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, bool remoteCertRequired) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcceptSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + Logging.ObjectToString(context) + ", " + "remoteCertRequired = " + remoteCertRequired); } return(SecModule.AcceptSecurityContext(ref credential, ref context, inputBuffer, outputBuffer, remoteCertRequired)); }
internal HttpListenerContext(HttpListener httpListener, RequestContextBase memoryBlob) { if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, ".ctor", "httpListener#" + ValidationHelper.HashString(httpListener) + " requestBlob=" + ValidationHelper.HashString((IntPtr)memoryBlob.RequestBlob)); } m_Listener = httpListener; m_Request = new HttpListenerRequest(this, memoryBlob); m_AuthenticationSchemes = httpListener.AuthenticationSchemes; m_ExtendedProtectionPolicy = httpListener.ExtendedProtectionPolicy; GlobalLog.Print("HttpListenerContext#" + ValidationHelper.HashString(this) + "::.ctor() HttpListener#" + ValidationHelper.HashString(m_Listener) + " HttpListenerRequest#" + ValidationHelper.HashString(m_Request)); }
public void AppendCookie(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, "AppendCookie", " cookie#" + ValidationHelper.HashString(cookie)); } Cookies.Add(cookie); }
internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterface secModule) { GlobalLog.Enter("EnumerateSecurityPackages"); if (secModule.SecurityPackages == null) { lock (secModule) { if (secModule.SecurityPackages == null) { int moduleCount = 0; SafeFreeContextBuffer arrayBaseHandle = null; try { int errorCode = secModule.EnumerateSecurityPackages(out moduleCount, out arrayBaseHandle); GlobalLog.Print("SSPIWrapper::arrayBase: " + (arrayBaseHandle.DangerousGetHandle().ToString("x"))); if (errorCode != 0) { throw new Win32Exception(errorCode); } SecurityPackageInfoClass[] securityPackages = new SecurityPackageInfoClass[moduleCount]; if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.net_log_sspi_enumerating_security_packages); } int i; for (i = 0; i < moduleCount; i++) { securityPackages[i] = new SecurityPackageInfoClass(arrayBaseHandle, i); if (Logging.On) { Logging.PrintInfo(Logging.Web, " " + securityPackages[i].Name); } } secModule.SecurityPackages = securityPackages; } finally { if (arrayBaseHandle != null) { arrayBaseHandle.Dispose(); } } } } } GlobalLog.Leave("EnumerateSecurityPackages"); return(secModule.SecurityPackages); }
private static ConcurrentDictionary <string, SafeFreeCredentials> InitDefaultCredentialsHandleCache() { if (Logging.On) { Logging.PrintInfo( Logging.Web, $"{nameof(InitDefaultCredentialsHandleCache)}: {System.Net.Configuration.ConfigurationStrings.DefaultCredentialsHandleCacheSize} = {s_DefaultCredentialsHandleCacheSize}"); } Debug.Assert(s_DefaultCredentialsHandleCacheSize > 0); return(new ConcurrentDictionary <string, SafeFreeCredentials>(Environment.ProcessorCount, s_DefaultCredentialsHandleCacheSize)); }
internal static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface SecModule, X509Certificate certificate, SslProtocols protocols, EncryptionPolicy policy, bool isServer) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcquireCredentialsHandle(" + "protocols = " + protocols + ", " + "policy = " + policy + ", " + "isServer = " + isServer + ")"); } return(SecModule.AcquireCredentialsHandle(certificate, protocols, policy, isServer)); }
// // This version of an Ssl Stream is for internal HttpWebrequest use. // This Ssl client owns the underlined socket // The TlsStream will own secured read/write and disposal of the passed "networkStream" stream. // public TlsStream( string destinationHost, NetworkStream networkStream, bool checkCertificateRevocationList, SslProtocols sslProtocols, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext) : base(networkStream, true) { m_CheckCertificateRevocationList = checkCertificateRevocationList; m_SslProtocols = sslProtocols; // WebRequest manages the execution context manually so we have to ensure we get one for SSL client certificate demand _ExecutionContext = executionContext; if (_ExecutionContext == null) { _ExecutionContext = ExecutionContext.Capture(); } // GlobalLog.Enter("TlsStream::TlsStream", "host=" + destinationHost + ", #certs=" + ((clientCertificates == null) ? "none" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo))); if (Logging.On) { Logging.PrintInfo( Logging.Web, this, ".ctor", string.Format( "host={0}, #certs={1}, checkCertificateRevocationList={2}, sslProtocols={3}", destinationHost, (clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo), checkCertificateRevocationList, sslProtocols)); } m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure; m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy); m_DestinationHost = destinationHost; m_ClientCertificates = clientCertificates; RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest); m_Worker.SetCertValidationDelegate(certValidationCallback); // The Handshake is NOT done at this point GlobalLog.Leave("TlsStream::TlsStream (Handshake is not done)"); }
/*++ ResponseStream - Return the response stream. This property returns the response stream for this response. The response stream will do de-chunking, etc. as needed. Input: Nothing. Property is readonly. Returns: Response stream for response. --*/ /// <devdoc> /// <para>Gets the stream used for reading the body of the response from the /// server.</para> /// </devdoc> public override Stream GetResponseStream() { if(Logging.On)Logging.Enter(Logging.Web, this, "GetResponseStream", ""); CheckDisposed(); if (!CanGetResponseStream()) { // give a blank stream in the HEAD case, which = 0 bytes of data if(Logging.On)Logging.Exit(Logging.Web, this, "GetResponseStream", Stream.Null); return Stream.Null; } if(Logging.On)Logging.PrintInfo(Logging.Web, "ContentLength="+m_ContentLength); if(Logging.On)Logging.Exit(Logging.Web, this, "GetResponseStream", m_ConnectStream); return m_ConnectStream; }
internal static int AcceptSecurityContext(SSPIInterface SecModule, ref SafeFreeCredentials credential, ref SafeDeleteContext context, ContextFlags inFlags, Endianness datarep, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ref ContextFlags outFlags) { if (Logging.On) { Logging.PrintInfo(Logging.Web, string.Concat(new object[] { "AcceptSecurityContext(credential = ", credential.ToString(), ", context = ", ValidationHelper.ToString(context), ", inFlags = ", inFlags, ")" })); } int num = SecModule.AcceptSecurityContext(ref credential, ref context, inputBuffer, inFlags, datarep, outputBuffer, ref outFlags); if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.GetString("net_log_sspi_security_context_input_buffer", new object[] { "AcceptSecurityContext", (inputBuffer == null) ? 0 : inputBuffer.size, outputBuffer.size, (SecurityStatus)num })); } return(num); }
internal HttpListenerResponse() { if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, ".ctor", ""); } m_NativeResponse = new UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE(); m_WebHeaders = new WebHeaderCollection(WebHeaderCollectionType.HttpListenerResponse); m_BoundaryType = BoundaryType.None; m_NativeResponse.StatusCode = (ushort)HttpStatusCode.OK; m_NativeResponse.Version.MajorVersion = 1; m_NativeResponse.Version.MinorVersion = 1; m_KeepAlive = true; m_ResponseState = ResponseState.Created; }
internal static SecurityStatus InitializeSecurityContext(SSPIInterface SecModule, SafeFreeCredentials credential, ref SafeDeleteContext context, string targetName, SecurityBuffer[] inputBuffers, SecurityBuffer outputBuffer) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "InitializeSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + Logging.ObjectToString(context) + ", " + "targetName = " + targetName); } SecurityStatus errorCode = SecModule.InitializeSecurityContext(credential, ref context, targetName, inputBuffers, outputBuffer); return(errorCode); }
private static void IdleServicePointTimeoutCallback(TimerThread.Timer timer, int timeNoticed, object context) { ServicePoint servicePoint = (ServicePoint)context; if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.GetString(SR.net_log_closed_idle, "ServicePoint", servicePoint.GetHashCode())); } lock (s_ServicePointTable) { s_ServicePointTable.Remove(servicePoint.LookupString); } servicePoint.ReleaseAllConnectionGroups(); }
public override Stream GetResponseStream() { if (Logging.On) { Logging.Enter(Logging.Web, this, "GetResponseStream", ""); } this.CheckDisposed(); if (Logging.On) { Logging.PrintInfo(Logging.Web, "ContentLength=" + this.m_ContentLength); } if (Logging.On) { Logging.Exit(Logging.Web, this, "GetResponseStream", this.m_ConnectStream); } return(this.m_ConnectStream); }
public void CopyFrom(HttpListenerResponse templateResponse) { if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, "CopyFrom", "templateResponse#" + ValidationHelper.HashString(templateResponse)); } m_NativeResponse = new UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE(); m_ResponseState = ResponseState.Created; m_WebHeaders = templateResponse.m_WebHeaders; m_BoundaryType = templateResponse.m_BoundaryType; m_ContentLength = templateResponse.m_ContentLength; m_NativeResponse.StatusCode = templateResponse.m_NativeResponse.StatusCode; m_NativeResponse.Version.MajorVersion = templateResponse.m_NativeResponse.Version.MajorVersion; m_NativeResponse.Version.MinorVersion = templateResponse.m_NativeResponse.Version.MinorVersion; m_StatusDescription = templateResponse.m_StatusDescription; m_KeepAlive = templateResponse.m_KeepAlive; }
private static bool LoadReusePortConfiguration(bool reusePortInternal) { int reusePortKeyValue = 0; reusePortKeyValue = RegistryConfiguration.GlobalConfigReadInt(RegistryGlobalReusePortName, 0); if (reusePortKeyValue == 1) { if (Logging.On) { Logging.PrintInfo(Logging.Web, typeof(ServicePointManager), SR.GetString(SR.net_log_set_socketoption_reuseport_default_on)); } reusePortInternal = true; } return(reusePortInternal); }
internal static SecurityPackageInfoClass[] EnumerateSecurityPackages(SSPIInterface SecModule) { if (SecModule.SecurityPackages == null) { lock (SecModule) { if (SecModule.SecurityPackages == null) { int pkgnum = 0; SafeFreeContextBuffer pkgArray = null; try { int error = SecModule.EnumerateSecurityPackages(out pkgnum, out pkgArray); if (error != 0) { throw new Win32Exception(error); } SecurityPackageInfoClass[] classArray = new SecurityPackageInfoClass[pkgnum]; if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.GetString("net_log_sspi_enumerating_security_packages")); } for (int i = 0; i < pkgnum; i++) { classArray[i] = new SecurityPackageInfoClass(pkgArray, i); if (Logging.On) { Logging.PrintInfo(Logging.Web, " " + classArray[i].Name); } } SecModule.SecurityPackages = classArray; } finally { if (pkgArray != null) { pkgArray.Close(); } } } } } return(SecModule.SecurityPackages); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface SecModule, string package, CredentialUse intent) { if (Logging.On) { Logging.PrintInfo(Logging.Web, string.Concat(new object[] { "AcquireDefaultCredential(package = ", package, ", intent = ", intent, ")" })); } SafeFreeCredentials outCredential = null; int error = SecModule.AcquireDefaultCredential(package, intent, out outCredential); if (error == 0) { return(outCredential); } if (Logging.On) { Logging.PrintError(Logging.Web, SR.GetString("net_log_operation_failed_with_error", new object[] { "AcquireDefaultCredential()", string.Format(CultureInfo.CurrentCulture, "0X{0:X}", new object[] { error }) })); } throw new Win32Exception(error); }
public void SetCookie(Cookie cookie) { if (cookie == null) { throw new ArgumentNullException("cookie"); } Cookie new_cookie = cookie.Clone(); int added = Cookies.InternalAdd(new_cookie, true); if (Logging.On) { Logging.PrintInfo(Logging.HttpListener, this, "SetCookie", " cookie#" + ValidationHelper.HashString(cookie)); } if (added != 1) { // cookie already existed and couldn't be replaced throw new ArgumentException(SR.GetString(SR.net_cookie_exists), "cookie"); } }
public TlsStream(string destinationHost, NetworkStream networkStream, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext) : base(networkStream, true) { this.m_PendingIO = new ArrayList(); this._ExecutionContext = executionContext; if (this._ExecutionContext == null) { this._ExecutionContext = ExecutionContext.Capture(); } if (Logging.On) { Logging.PrintInfo(Logging.Web, this, ".ctor", "host=" + destinationHost + ", #certs=" + ((clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo))); } this.m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure; this.m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy); this.m_DestinationHost = destinationHost; this.m_ClientCertificates = clientCertificates; RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest); this.m_Worker.SetCertValidationDelegate(certValidationCallback); }
internal static int AcceptSecurityContext(SSPIInterface SecModule, SafeFreeCredentials credential, ref SafeDeleteContext context, ContextFlags inFlags, Endianness datarep, SecurityBuffer[] inputBuffers, SecurityBuffer outputBuffer, ref ContextFlags outFlags) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcceptSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + ValidationHelper.ToString(context) + ", " + "inFlags = " + inFlags + ")"); } int errorCode = SecModule.AcceptSecurityContext(credential, ref context, inputBuffers, inFlags, datarep, outputBuffer, ref outFlags); if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.GetString(SR.net_log_sspi_security_context_input_buffers, "AcceptSecurityContext", (inputBuffers == null ? 0 : inputBuffers.Length), outputBuffer.size, (SecurityStatus)errorCode)); } return(errorCode); }
internal static int AcceptSecurityContext(SSPIInterface secModule, ref SafeFreeCredentials credential, ref SafeDeleteContext context, Interop.Secur32.ContextFlags inFlags, Interop.Secur32.Endianness datarep, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer, ref Interop.Secur32.ContextFlags outFlags) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcceptSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + Logging.ObjectToString(context) + ", " + "inFlags = " + inFlags + ")"); } int errorCode = secModule.AcceptSecurityContext(ref credential, ref context, inputBuffer, inFlags, datarep, outputBuffer, ref outFlags); if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_sspi_security_context_input_buffer, "AcceptSecurityContext", (inputBuffer == null ? 0 : inputBuffer.size), outputBuffer.size, (Interop.SecurityStatus)errorCode)); } return(errorCode); }
public bool Remove(string uriPrefix) { string newServiceName = this.BuildSimpleServiceName(uriPrefix); bool flag = this.Contains(newServiceName); if (flag) { this.serviceNames.Remove(newServiceName); this.serviceNameCollection = null; } if (Logging.On) { if (flag) { Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Remove() removing default SPN '" + newServiceName + "' from prefix '" + uriPrefix + "'"); return(flag); } Logging.PrintInfo(Logging.HttpListener, "ServiceNameStore#" + ValidationHelper.HashString(this) + "::Remove() no default SPN removed for prefix '" + uriPrefix + "'"); } return(flag); }
internal static SecurityStatus InitializeSecurityContext(SSPIInterface SecModule, ref SafeFreeCredentials credential, ref SafeDeleteContext context, string targetName, SecurityBuffer inputBuffer, SecurityBuffer outputBuffer) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "InitializeSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + Logging.ObjectToString(context) + ", " + "targetName = " + targetName); } SecurityStatus errorCode = SecModule.InitializeSecurityContext(ref credential, ref context, targetName, inputBuffer, outputBuffer); if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_sspi_security_context_input_buffer, "InitializeSecurityContext", (inputBuffer == null ? 0 : inputBuffer.size), outputBuffer.size, (SecurityStatus)errorCode)); } return(errorCode); }
internal static int InitializeSecurityContext(SSPIInterface secModule, SafeFreeCredentials credential, ref SafeDeleteContext context, string targetName, Interop.Secur32.ContextFlags inFlags, Interop.Secur32.Endianness datarep, SecurityBuffer[] inputBuffers, SecurityBuffer outputBuffer, ref Interop.Secur32.ContextFlags outFlags) { if (Logging.On) { Logging.PrintInfo(Logging.Web, "InitializeSecurityContext(" + "credential = " + credential.ToString() + ", " + "context = " + Logging.ObjectToString(context) + ", " + "targetName = " + targetName + ", " + "inFlags = " + inFlags + ")"); } int errorCode = secModule.InitializeSecurityContext(credential, ref context, targetName, inFlags, datarep, inputBuffers, outputBuffer, ref outFlags); if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_sspi_security_context_input_buffers, "InitializeSecurityContext", (inputBuffers == null ? 0 : inputBuffers.Length), outputBuffer.size, (Interop.SecurityStatus)errorCode)); } return(errorCode); }
// // Extracts a remote certificate upon request. // internal static X509Certificate2 GetRemoteCertificate(SafeDeleteContext securityContext, out X509Certificate2Collection remoteCertificateStore) { remoteCertificateStore = null; if (securityContext == null) { return(null); } GlobalLog.Enter("CertificateValidationPal.Windows SecureChannel#" + Logging.HashString(securityContext) + "::GetRemoteCertificate()"); X509Certificate2 result = null; SafeFreeCertContext remoteContext = null; try { remoteContext = SSPIWrapper.QueryContextAttributes(GlobalSSPI.SSPISecureChannel, securityContext, Interop.Secur32.ContextAttribute.RemoteCertificate) as SafeFreeCertContext; if (remoteContext != null && !remoteContext.IsInvalid) { result = new X509Certificate2(remoteContext.DangerousGetHandle()); } } finally { if (remoteContext != null && !remoteContext.IsInvalid) { remoteCertificateStore = UnmanagedCertificateContext.GetRemoteCertificatesFromStoreContext(remoteContext); remoteContext.Dispose(); } } if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_remote_certificate, (result == null ? "null" : result.ToString(true)))); } GlobalLog.Leave("CertificateValidationPal.Windows SecureChannel#" + Logging.HashString(securityContext) + "::GetRemoteCertificate()", (result == null ? "null" : result.Subject)); return(result); }
// // Extracts a remote certificate upon request. // internal override X509Certificate2 GetRemoteCertificate(SafeDeleteContext securityContext, out X509Certificate2Collection remoteCertificateStore) { remoteCertificateStore = null; if (securityContext == null) { return(null); } GlobalLog.Enter("SecureChannel#" + Logging.HashString(this) + "::RemoteCertificate{get;}"); X509Certificate2 result = null; SafeFreeCertContext remoteContext = null; try { int errorCode = SSPIWrapper.QueryContextRemoteCertificate(GlobalSSPI.SSPISecureChannel, securityContext, out remoteContext); if (remoteContext != null && !remoteContext.IsInvalid) { result = new X509Certificate2(remoteContext.DangerousGetHandle()); } } finally { if (remoteContext != null && !remoteContext.IsInvalid) { remoteCertificateStore = UnmanagedCertificateContext.GetRemoteCertificatesFromStoreContext(remoteContext); remoteContext.Dispose(); } } if (Logging.On) { Logging.PrintInfo(Logging.Web, SR.Format(SR.net_log_remote_certificate, (result == null ? "null" : result.ToString(true)))); } GlobalLog.Leave("SecureChannel#" + Logging.HashString(this) + "::RemoteCertificate{get;}", (result == null ? "null" : result.Subject)); return(result); }
public static SafeFreeCredentials AcquireCredentialsHandle(SSPIInterface secModule, string package, Interop.Secur32.CredentialUse intent, Interop.Secur32.SecureCredential scc) { GlobalLog.Print("SSPIWrapper::AcquireCredentialsHandle#3(): using " + package); if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcquireCredentialsHandle(" + "package = " + package + ", " + "intent = " + intent + ", " + "scc = " + scc + ")"); } SafeFreeCredentials outCredential = null; int errorCode = secModule.AcquireCredentialsHandle( package, intent, ref scc, out outCredential ); if (errorCode != 0) { #if TRACE_VERBOSE GlobalLog.Print("SSPIWrapper::AcquireCredentialsHandle#3(): error " + Interop.MapSecurityStatus((uint)errorCode)); #endif if (Logging.On) { Logging.PrintError(Logging.Web, SR.Format(SR.net_log_operation_failed_with_error, "AcquireCredentialsHandle()", String.Format(CultureInfo.CurrentCulture, "0X{0:X}", errorCode))); } throw new Win32Exception(errorCode); } #if TRACE_VERBOSE GlobalLog.Print("SSPIWrapper::AcquireCredentialsHandle#3(): cred handle = " + outCredential.ToString()); #endif return(outCredential); }
internal virtual void ConnectionCallback(object owningObject, Exception e, Socket socket, IPAddress address) { GlobalLog.Assert(owningObject == Owner || Owner == null, "PooledStream::ConnectionCallback|Owner is not the same as expected."); object result = null; if (e != null) { m_Initalizing = false; result = e; } else { try { if (Logging.On) { Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_socket_connected, socket.LocalEndPoint, socket.RemoteEndPoint)); } m_NetworkStream.InitNetworkStream(socket, FileAccess.ReadWrite); result = this; } catch (Exception ex) { if (NclUtilities.IsFatal(ex)) { throw; } result = ex; } m_ServerAddress = address; m_Initalizing = false; m_JustConnected = true; } if (m_AsyncCallback != null) { m_AsyncCallback(owningObject, result); } m_AbortSocket = null; m_AbortSocket6 = null; }
protected bool Activate(object owningObject, bool async, int timeout, GeneralAsyncDelegate asyncCallback) { bool flag; try { if (this.m_Initalizing) { IPAddress address = null; this.m_AsyncCallback = asyncCallback; System.Net.Sockets.Socket socket = this.ServicePoint.GetConnection(this, owningObject, async, out address, ref this.m_AbortSocket, ref this.m_AbortSocket6, timeout); if (socket != null) { if (Logging.On) { Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_socket_connected", new object[] { socket.LocalEndPoint, socket.RemoteEndPoint })); } this.m_NetworkStream.InitNetworkStream(socket, FileAccess.ReadWrite); this.m_ServerAddress = address; this.m_Initalizing = false; this.m_JustConnected = true; this.m_AbortSocket = null; this.m_AbortSocket6 = null; return(true); } return(false); } if (async && (asyncCallback != null)) { asyncCallback(owningObject, this); } flag = true; } catch { this.m_Initalizing = false; throw; } return(flag); }
internal virtual void ConnectionCallback(object owningObject, Exception e, System.Net.Sockets.Socket socket, IPAddress address) { object state = null; if (e != null) { this.m_Initalizing = false; state = e; } else { try { if (Logging.On) { Logging.PrintInfo(Logging.Web, this, SR.GetString("net_log_socket_connected", new object[] { socket.LocalEndPoint, socket.RemoteEndPoint })); } this.m_NetworkStream.InitNetworkStream(socket, FileAccess.ReadWrite); state = this; } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } state = exception; } this.m_ServerAddress = address; this.m_Initalizing = false; this.m_JustConnected = true; } if (this.m_AsyncCallback != null) { this.m_AsyncCallback(owningObject, state); } this.m_AbortSocket = null; this.m_AbortSocket6 = null; }