Backported fixes from HEAD
[mono.git] / mcs / class / System / System.Net / HttpStateCache.jvm.cs
1 using System;\r
2 using System.Collections;\r
3 \r
4 using mainsoft.apache.commons.httpclient;\r
5 \r
6 namespace System.Net\r
7 {\r
8         \r
9         class HttpStateCache\r
10         {\r
11                 private static readonly int MAX_SIZE = 30;\r
12 \r
13                 private Stack _states;\r
14                 private int _currentSize;\r
15 \r
16                 internal HttpStateCache()\r
17                 {\r
18                         _states = new Stack(20);\r
19                 }\r
20 \r
21                 internal HttpState GetHttpState()\r
22                 {\r
23                         lock(this)\r
24                         {\r
25                                 if(_states.Count > 0)\r
26                                         return (HttpState) _states.Pop();\r
27                         }\r
28                         return new HttpState();\r
29                 }\r
30 \r
31                 internal void ReleaseHttpState(HttpState state)\r
32                 {\r
33                         lock(this)\r
34                         {\r
35                                 if(_states.Count < MAX_SIZE)\r
36                                 {\r
37                                         state.clear();\r
38                                         _states.Push(state);\r
39                                 }\r
40                         }\r
41                 }\r
42         }\r
43 }\r