Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FtpAsyncResult.cs « System.Net « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c8aac452e05573f3b03bb15464bb7afc0b61c0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//
// System.Net.FtpAsyncResult.cs
//
// Authors:
//	Carlos Alberto Cortez (calberto.cortez@gmail.com)
//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//

using System;
using System.IO;
using System.Threading;

#if NET_2_0

namespace System.Net 
{
	class FtpAsyncResult : IAsyncResult
	{
		FtpWebResponse response;
		ManualResetEvent waitHandle;
		Exception exception;
		AsyncCallback callback;
		Stream stream;
		object state;
		bool completed;
		bool synch;
		object locker = new object ();

		public FtpAsyncResult (AsyncCallback callback, object state)
		{
			this.callback = callback;
			this.state = state;
		}
		
		public object AsyncState {
			get {
				return state;
			}
		}

		public WaitHandle AsyncWaitHandle {
			get {
				lock (locker) {
					if (waitHandle == null)
						waitHandle = new ManualResetEvent (false);
				}
				
				return waitHandle;
			}
		}

		public bool CompletedSynchronously {
			get {
				return synch;
			}
		}

		public bool IsCompleted {
			get {
				lock (locker) {
					return completed;
				}
			}
		}

		internal bool GotException {
			get {
				return exception != null;
			}
		}

		internal Exception Exception {
			get {
				return exception;
			}
		}

		internal FtpWebResponse Response {
			get {
				return response;
			}
			set {
				response = value;
			}
		}

		internal Stream Stream {
			get {
				return stream;
			}
		}

		internal void WaitUntilComplete ()
		{
			if (IsCompleted)
				return;

			AsyncWaitHandle.WaitOne ();
		}

		internal bool WaitUntilComplete (int timeout, bool exitContext)
		{
			if (IsCompleted)
				return true;
			
			return AsyncWaitHandle.WaitOne (timeout, exitContext);
		}

		internal void SetCompleted (bool synch, Exception exc, FtpWebResponse response)
		{
			this.synch = synch;
			this.exception = exc;
			this.response = response;
			lock (locker) {
				completed = true;
				if (waitHandle != null)
					waitHandle.Set ();
			}
		}

		internal void SetCompleted (bool synch)
		{
			SetCompleted (synch, null, null);
		}

		internal void SetCompleted (bool synch, FtpWebResponse response)
		{
			SetCompleted (synch, null, response);
		}

		internal void SetCompleted (bool synch, Exception exc)
		{
			SetCompleted (synch, exc, null);
		}

		internal void SetCompleted (bool synch, Stream stream)
		{
			this.synch = synch;
			this.stream = stream;
			lock (locker) {
				completed = true;
				if (waitHandle != null)
					waitHandle.Set ();
			}
		}

		internal void DoCallback ()
		{
			callback (this);
		}

		// Cleanup resources
		internal void Reset () 
		{
			exception = null;
			synch = false;
			response = null;
			state = null;
			
			lock (locker) {
				completed = false;
				if (waitHandle != null)
					waitHandle.Reset ();
			}
		}
		
	}
}

#endif