} // CachedSocketList internal SocketHandler GetSocket() { if (_socketCount == 0) { return(null); } lock (this) { if (_socketList != null) { SocketHandler socket = _socketList.Handler; _socketList = _socketList.Next; bool bRes = socket.---- ForControl(); // We should always have control since there shouldn't // be contention here. InternalRemotingServices.RemotingAssert(bRes, "someone else has the socket?"); _socketCount--; return(socket); } } return(null); } // GetSocket
internal void ReturnSocket(SocketHandler socket) { TimeSpan span = (TimeSpan) (DateTime.UtcNow - socket.CreationTime); bool flag = false; lock (this) { if ((this._socketCachePolicy != SocketCachePolicy.AbsoluteTimeout) || (span < this._socketLifetime)) { for (CachedSocket socket2 = this._socketList; socket2 != null; socket2 = socket2.Next) { if (socket == socket2.Handler) { return; } } this._socketList = new CachedSocket(socket, this._socketList); this._socketCount++; } else { flag = true; } } if (flag) { socket.Close(); } }
private CachedSocket _socketList; // linked list internal CachedSocketList(TimeSpan socketLifetime, SocketCachePolicy socketCachePolicy) { _socketCount = 0; _socketLifetime = socketLifetime; _socketCachePolicy = socketCachePolicy; _socketList = null; } // CachedSocketList
internal CachedSocket(SocketHandler socket, CachedSocket next) { _socket = socket; _socketLastUsed = DateTime.Now; _next = next; } // CachedSocket
internal void TimeoutSockets(DateTime currentTime, TimeSpan socketLifetime) { lock (this) { CachedSocket socket = null; CachedSocket next = this._socketList; while (next != null) { if (((this._socketCachePolicy == SocketCachePolicy.AbsoluteTimeout) && ((currentTime - next.Handler.CreationTime) > socketLifetime)) || ((currentTime - next.LastUsed) > socketLifetime)) { next.Handler.Close(); if (socket == null) { this._socketList = next.Next; next = this._socketList; } else { next = next.Next; socket.Next = next; } this._socketCount--; } else { socket = next; next = next.Next; } } } }
} // GetSocket internal void ReturnSocket(SocketHandler socket) { TimeSpan socketActiveTime = DateTime.UtcNow - socket.CreationTime; bool closeSocket = false; lock (this) { // Check if socket active time has exceeded the lifetime // If it has just close the Socket if (_socketCachePolicy != SocketCachePolicy.AbsoluteTimeout || socketActiveTime < _socketLifetime) { // Ignore duplicate entries for the same socket handler for (CachedSocket curr = _socketList; curr != null; curr = curr.Next) { if (socket == curr.Handler) { return; } } _socketList = new CachedSocket(socket, _socketList); _socketCount++; } else { closeSocket = true; } } if (closeSocket) { socket.Close(); } } // ReturnSocket
} // GetSocket internal void ReturnSocket(SocketHandler socket) { lock (this) { _socketList = new CachedSocket(socket, _socketList); _socketCount++; } } // ReturnSocket
internal SocketHandler GetSocket() { if (this._socketCount != 0) { lock (this) { if (this._socketList != null) { SocketHandler handler = this._socketList.Handler; this._socketList = this._socketList.Next; handler.RaceForControl(); this._socketCount--; return handler; } } } return null; }
} // ReturnSocket internal void TimeoutSockets(DateTime currentTime, TimeSpan socketLifetime) { lock (this) { CachedSocket prev = null; CachedSocket curr = _socketList; while (curr != null) { // see if it's lifetime has expired if ((_socketCachePolicy == SocketCachePolicy.AbsoluteTimeout && // This is for absolute (currentTime - curr.Handler.CreationTime) > socketLifetime) || (currentTime - curr.LastUsed) > socketLifetime) // This is relative behaviour { curr.Handler.Close(); // remove current cached socket from list if (prev == null) { // it's the first item, so update _socketList _socketList = curr.Next; curr = _socketList; } else { // remove current item from the list curr = curr.Next; prev.Next = curr; } // decrement socket count _socketCount--; } else { prev = curr; curr = curr.Next; } } } } // TimeoutSockets
private CachedSocket _socketList; // linked list internal CachedSocketList() { _socketCount = 0; _socketList = null; } // CachedSocketList
} // CachedSocketList internal SocketHandler GetSocket() { if (_socketCount == 0) return null; lock (this) { if (_socketList != null) { SocketHandler socket = _socketList.Handler; _socketList = _socketList.Next; bool bRes = socket.RaceForControl(); // We should always have control since there shouldn't // be contention here. InternalRemotingServices.RemotingAssert(bRes, "someone else has the socket?"); _socketCount--; return socket; } } return null; } // GetSocket
} // GetSocket internal void ReturnSocket(SocketHandler socket) { TimeSpan socketActiveTime = DateTime.UtcNow - socket.CreationTime; bool closeSocket = false; lock (this) { // Check if socket active time has exceeded the lifetime // If it has just close the Socket if (_socketCachePolicy != SocketCachePolicy.AbsoluteTimeout || socketActiveTime < _socketLifetime) { // Ignore duplicate entries for the same socket handler for (CachedSocket curr = _socketList; curr != null; curr = curr.Next){ if (socket == curr.Handler) return; } _socketList = new CachedSocket(socket, _socketList); _socketCount++; } else { closeSocket = true; } } if(closeSocket) { socket.Close(); } } // ReturnSocket
} // ReturnSocket internal void TimeoutSockets(DateTime currentTime, TimeSpan socketLifetime) { lock (this) { CachedSocket prev = null; CachedSocket curr = _socketList; while (curr != null) { // see if it's lifetime has expired if ((currentTime - curr.LastUsed) > socketLifetime) { curr.Handler.Close(); // remove current cached socket from list if (prev == null) { // it's the first item, so update _socketList _socketList = curr.Next; curr = _socketList; } else { // remove current item from the list curr = curr.Next; prev.Next = curr; } // decrement socket count _socketCount--; } else { prev = curr; curr = curr.Next; } } } } // TimeoutSockets
internal CachedSocketList(TimeSpan socketLifetime, SocketCachePolicy socketCachePolicy) { this._socketLifetime = socketLifetime; this._socketCachePolicy = socketCachePolicy; this._socketList = null; }
internal CachedSocket(SocketHandler socket, CachedSocket next) { this._socket = socket; this._socketLastUsed = DateTime.UtcNow; this._next = next; }