internal override TimerThread.Timer CreateTimer(TimerThread.Callback callback, object context) { TimerThread.TimerNode node = new TimerThread.TimerNode(callback, context, base.Duration, this.m_Timers); bool flag = false; lock (this.m_Timers) { if (this.m_Timers.Next == this.m_Timers) { if (this.m_ThisHandle == IntPtr.Zero) { this.m_ThisHandle = (IntPtr)GCHandle.Alloc(this); } flag = true; } node.Next = this.m_Timers; node.Prev = this.m_Timers.Prev; this.m_Timers.Prev.Next = node; this.m_Timers.Prev = node; } if (flag) { TimerThread.Prod(); } return(node); }
internal TimerNode(TimerThread.Callback callback, object context, int durationMilliseconds, object queueLock) : base(durationMilliseconds) { if (callback != null) { this.m_Callback = callback; this.m_Context = context; } this.m_TimerState = TimerState.Ready; this.m_QueueLock = queueLock; }
internal bool Fire() { if (this.m_TimerState == TimerState.Ready) { int tickCount = Environment.TickCount; if (TimerThread.IsTickBetween(base.StartTime, base.Expiration, tickCount)) { return(false); } bool flag = false; lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.m_TimerState = TimerState.Fired; this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; flag = this.m_Callback != null; } } if (flag) { try { TimerThread.Callback callback = this.m_Callback; object context = this.m_Context; this.m_Callback = null; this.m_Context = null; callback(this, tickCount, context); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } if (Logging.On) { Logging.PrintError(Logging.Web, "TimerThreadTimer#" + base.StartTime.ToString(NumberFormatInfo.InvariantInfo) + "::Fire() - " + SR.GetString("net_log_exception_in_callback", new object[] { exception })); } } } } return(true); }
internal override bool Cancel() { if (this.m_TimerState == TimerState.Ready) { lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; this.m_Callback = null; this.m_Context = null; this.m_TimerState = TimerState.Cancelled; return(true); } } } return(false); }
internal FtpWebRequest(Uri uri) { new WebPermission(NetworkAccess.Connect, uri).Demand(); if (Logging.On) { Logging.PrintInfo(Logging.Web, this, ".ctor", uri.ToString()); } if (uri.Scheme != Uri.UriSchemeFtp) { throw new ArgumentOutOfRangeException("uri"); } this.m_TimerCallback = new TimerThread.Callback(this.TimerCallback); this.m_SyncObject = new object(); NetworkCredential defaultFtpNetworkCredential = null; this.m_Uri = uri; this.m_MethodInfo = FtpMethodInfo.GetMethodInfo("RETR"); if ((this.m_Uri.UserInfo != null) && (this.m_Uri.UserInfo.Length != 0)) { string userInfo = this.m_Uri.UserInfo; string userName = userInfo; string password = ""; int index = userInfo.IndexOf(':'); if (index != -1) { userName = Uri.UnescapeDataString(userInfo.Substring(0, index)); index++; password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index)); } defaultFtpNetworkCredential = new NetworkCredential(userName, password); } if (defaultFtpNetworkCredential == null) { defaultFtpNetworkCredential = DefaultFtpNetworkCredential; } this.m_AuthInfo = defaultFtpNetworkCredential; base.SetupCacheProtocol(this.m_Uri); }
internal FtpWebRequest(Uri uri) { if (NetEventSource.IsEnabled) NetEventSource.Info(this, uri); if ((object)uri.Scheme != (object)Uri.UriSchemeFtp) throw new ArgumentOutOfRangeException(nameof(uri)); _timerCallback = new TimerThread.Callback(TimerCallback); _syncObject = new object(); NetworkCredential networkCredential = null; _uri = uri; _methodInfo = FtpMethodInfo.GetMethodInfo(WebRequestMethods.Ftp.DownloadFile); if (_uri.UserInfo != null && _uri.UserInfo.Length != 0) { string userInfo = _uri.UserInfo; string username = userInfo; string password = ""; int index = userInfo.IndexOf(':'); if (index != -1) { username = Uri.UnescapeDataString(userInfo.Substring(0, index)); index++; // skip ':' password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index)); } networkCredential = new NetworkCredential(username, password); } if (networkCredential == null) { networkCredential = s_defaultFtpNetworkCredential; } _authInfo = networkCredential; }
/// <summary> /// <para> /// Initializes a new instance of the <see cref='System.Net.FtpWebRequest'/> /// class. /// </para> /// </summary> internal FtpWebRequest(Uri uri) { (new WebPermission(NetworkAccess.Connect, uri)).Demand(); if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", uri.ToString()); if ((object)uri.Scheme != (object)Uri.UriSchemeFtp) throw new ArgumentOutOfRangeException("uri"); m_TimerCallback = new TimerThread.Callback(TimerCallback); m_SyncObject = new object(); NetworkCredential networkCredential = null; m_Uri = uri; m_MethodInfo = FtpMethodInfo.GetMethodInfo(WebRequestMethods.Ftp.DownloadFile); if (m_Uri.UserInfo != null && m_Uri.UserInfo.Length != 0) { string userInfo = m_Uri.UserInfo; string username = userInfo; string password = ""; int index = userInfo.IndexOf(':'); if (index != -1) { username = Uri.UnescapeDataString(userInfo.Substring(0, index)); index++; // skip ':' password = Uri.UnescapeDataString(userInfo.Substring(index, userInfo.Length - index)); } networkCredential = new NetworkCredential(username, password); } if (networkCredential == null) { networkCredential = DefaultFtpNetworkCredential; } m_AuthInfo = networkCredential; SetupCacheProtocol(m_Uri); }
internal ServicePoint(string host, int port, TimerThread.Queue defaultIdlingQueue, int defaultConnectionLimit, string lookupString, bool userChangedLimit, bool proxyServicePoint) { GlobalLog.Print("ServicePoint#" + ValidationHelper.HashString(this) + "::.ctor(" + lookupString+")"); if (Logging.On) Logging.Enter(Logging.Web, this, "ServicePoint", host + ":" + port); m_ProxyServicePoint = proxyServicePoint; m_ConnectionName = "ByHost:"+host+":"+port.ToString(CultureInfo.InvariantCulture); m_IdlingQueue = defaultIdlingQueue; m_ConnectionLimit = defaultConnectionLimit; m_HostLoopbackGuess = TriState.Unspecified; m_LookupString = lookupString; m_UserChangedLimit = userChangedLimit; m_ConnectionGroupList = new Hashtable(10); m_ConnectionLeaseTimeout = System.Threading.Timeout.Infinite; m_ReceiveBufferSize = -1; m_Host = host; m_Port = port; m_HostMode = true; // upon creation, the service point should be idle, by default m_IdleSince = DateTime.Now; m_ExpiringTimer = m_IdlingQueue.CreateTimer(ServicePointManager.IdleServicePointTimeoutDelegate, this); m_IdleConnectionGroupTimeoutDelegate = new TimerThread.Callback(IdleConnectionGroupTimeoutCallback); }
// // constructors // internal ServicePoint(Uri address, TimerThread.Queue defaultIdlingQueue, int defaultConnectionLimit, string lookupString, bool userChangedLimit, bool proxyServicePoint) { GlobalLog.Print("ServicePoint#" + ValidationHelper.HashString(this) + "::.ctor(" + lookupString+")"); if (Logging.On) Logging.Enter(Logging.Web, this, "ServicePoint", address.DnsSafeHost + ":" + address.Port); m_ProxyServicePoint = proxyServicePoint; m_Address = address; m_ConnectionName = address.Scheme; m_Host = address.DnsSafeHost; m_Port = address.Port; m_IdlingQueue = defaultIdlingQueue; m_ConnectionLimit = defaultConnectionLimit; m_HostLoopbackGuess = TriState.Unspecified; m_LookupString = lookupString; m_UserChangedLimit = userChangedLimit; m_UseNagleAlgorithm = ServicePointManager.UseNagleAlgorithm; m_Expect100Continue = ServicePointManager.Expect100Continue; m_ConnectionGroupList = new Hashtable(10); m_ConnectionLeaseTimeout = System.Threading.Timeout.Infinite; m_ReceiveBufferSize = -1; m_UseTcpKeepAlive = ServicePointManager.s_UseTcpKeepAlive; m_TcpKeepAliveTime = ServicePointManager.s_TcpKeepAliveTime; m_TcpKeepAliveInterval = ServicePointManager.s_TcpKeepAliveInterval; // it would be safer to make sure the server is 1.1 // but assume it is at the beginning, and update it later m_Understands100Continue = true; m_HttpBehaviour = HttpBehaviour.Unknown; // upon creation, the service point should be idle, by default m_IdleSince = DateTime.Now; m_ExpiringTimer = m_IdlingQueue.CreateTimer(ServicePointManager.IdleServicePointTimeoutDelegate, this); m_IdleConnectionGroupTimeoutDelegate = new TimerThread.Callback(IdleConnectionGroupTimeoutCallback); }
internal bool Fire() { if (this.m_TimerState == TimerState.Ready) { int tickCount = Environment.TickCount; if (TimerThread.IsTickBetween(base.StartTime, base.Expiration, tickCount)) { return false; } bool flag = false; lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.m_TimerState = TimerState.Fired; this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; flag = this.m_Callback != null; } } if (flag) { try { TimerThread.Callback callback = this.m_Callback; object context = this.m_Context; this.m_Callback = null; this.m_Context = null; callback(this, tickCount, context); } catch (Exception exception) { if (NclUtilities.IsFatal(exception)) { throw; } if (Logging.On) { Logging.PrintError(Logging.Web, string.Concat(new object[] { "TimerThreadTimer#", base.StartTime.ToString(NumberFormatInfo.InvariantInfo), "::Fire() - ", exception })); } } } } return true; }
internal override bool Cancel() { if (this.m_TimerState == TimerState.Ready) { lock (this.m_QueueLock) { if (this.m_TimerState == TimerState.Ready) { this.Next.Prev = this.Prev; this.Prev.Next = this.Next; this.Next = null; this.Prev = null; this.m_Callback = null; this.m_Context = null; this.m_TimerState = TimerState.Cancelled; return true; } } } return false; }
internal abstract TimerThread.Timer CreateTimer(TimerThread.Callback callback, object context);
internal override TimerThread.Timer CreateTimer(TimerThread.Callback callback, object context) { return(new TimerThread.InfiniteTimer()); }