Close() public méthode

public Close ( ) : void
Résultat void
Exemple #1
0
		public override void Abort ()
		{
			if (Interlocked.CompareExchange (ref aborted, 1, 0) == 1)
				return;

			if (haveResponse && finished_reading)
				return;

			haveResponse = true;
			if (abortHandler != null) {
				try {
					abortHandler (this, EventArgs.Empty);
				} catch (Exception) {}
				abortHandler = null;
			}

			if (asyncWrite != null) {
				WebAsyncResult r = asyncWrite;
				if (!r.IsCompleted) {
					try {
						WebException wexc = new WebException ("Aborted.", WebExceptionStatus.RequestCanceled); 
						r.SetCompleted (false, wexc);
						r.DoCallback ();
					} catch {}
				}
				asyncWrite = null;
			}			

			if (asyncRead != null) {
				WebAsyncResult r = asyncRead;
				if (!r.IsCompleted) {
					try {
						WebException wexc = new WebException ("Aborted.", WebExceptionStatus.RequestCanceled); 
						r.SetCompleted (false, wexc);
						r.DoCallback ();
					} catch {}
				}
				asyncRead = null;
			}			

			if (writeStream != null) {
				try {
					writeStream.Close ();
					writeStream = null;
				} catch {}
			}

			if (webResponse != null) {
				try {
					webResponse.Close ();
					webResponse = null;
				} catch {}
			}
		}		
Exemple #2
0
        public override void Abort()
        {
            haveResponse = true;
            aborted      = true;
            if (asyncWrite != null)
            {
                WebAsyncResult r    = asyncWrite;
                WebException   wexc = new WebException("Aborted.", WebExceptionStatus.RequestCanceled);
                r.SetCompleted(false, wexc);
                r.DoCallback();
                asyncWrite = null;
            }

            if (asyncRead != null)
            {
                WebAsyncResult r    = asyncRead;
                WebException   wexc = new WebException("Aborted.", WebExceptionStatus.RequestCanceled);
                r.SetCompleted(false, wexc);
                r.DoCallback();
                asyncRead = null;
            }

            if (abortHandler != null)
            {
                try {
                    abortHandler(this, EventArgs.Empty);
                } catch (Exception) {}
                abortHandler = null;
            }

            if (writeStream != null)
            {
                try {
                    writeStream.Close();
                    writeStream = null;
                } catch {}
            }

            if (webResponse != null)
            {
                try {
                    webResponse.Close();
                    webResponse = null;
                } catch {}
            }
        }
Exemple #3
0
        internal void SetWriteStream(WebConnectionStream stream)
        {
            if (aborted)
            {
                return;
            }

            writeStream = stream;
            if (bodyBuffer != null)
            {
                webHeaders.RemoveInternal("Transfer-Encoding");
                contentLength           = bodyBufferLength;
                writeStream.SendChunked = false;
            }

            SendRequestHeaders();

            haveRequest = true;

            if (bodyBuffer != null)
            {
                // The body has been written and buffered. The request "user"
                // won't write it again, so we must do it.
                writeStream.Write(bodyBuffer, 0, bodyBufferLength);
                bodyBuffer = null;
                writeStream.Close();
            }
            else if (method == "PUT" || method == "POST" || method == "OPTIONS")
            {
                if (getResponseCalled && !writeStream.RequestWritten)
                {
                    writeStream.WriteRequest();
                }
            }

            if (asyncWrite != null)
            {
                asyncWrite.SetCompleted(false, stream);
                asyncWrite.DoCallback();
                asyncWrite = null;
            }
        }
Exemple #4
0
		internal void SetWriteStream (WebConnectionStream stream)
		{
			if (Aborted)
				return;
			
			writeStream = stream;
			if (bodyBuffer != null) {
				webHeaders.RemoveInternal ("Transfer-Encoding");
				contentLength = bodyBufferLength;
				writeStream.SendChunked = false;
			}

			SendRequestHeaders (false);

			haveRequest = true;
			
			if (bodyBuffer != null) {
				// The body has been written and buffered. The request "user"
				// won't write it again, so we must do it.
				if (ntlm_auth_state != NtlmAuthState.Challenge) {
					writeStream.Write (bodyBuffer, 0, bodyBufferLength);
					bodyBuffer = null;
					writeStream.Close ();
				}
			} else if (method != "HEAD" && method != "GET" && method != "MKCOL" && method != "CONNECT" &&
					method != "TRACE") {
				if (getResponseCalled && !writeStream.RequestWritten)
					writeStream.WriteRequest ();
			}

			if (asyncWrite != null) {
				asyncWrite.SetCompleted (false, stream);
				asyncWrite.DoCallback ();
				asyncWrite = null;
			}
		}
Exemple #5
0
		internal void SetWriteStream (WebConnectionStream stream)
		{
			if (Aborted)
				return;
			
			writeStream = stream;
			if (bodyBuffer != null) {
				webHeaders.RemoveInternal ("Transfer-Encoding");
				contentLength = bodyBufferLength;
				writeStream.SendChunked = false;
			}

			SendRequestHeaders (false);

			haveRequest = true;
			
			if (bodyBuffer != null) {
				// The body has been written and buffered. The request "user"
				// won't write it again, so we must do it.
				if (ntlm_auth_state != NtlmAuthState.Challenge) {
					writeStream.Write (bodyBuffer, 0, bodyBufferLength);
					bodyBuffer = null;
					writeStream.Close ();
				}
			} else if (method != "HEAD" && method != "GET" && method != "MKCOL" && method != "CONNECT" &&
					method != "TRACE") {
				if (getResponseCalled && !writeStream.RequestWritten)
					writeStream.WriteRequest ();
			}

			if (asyncWrite != null) {
				asyncWrite.SetCompleted (false, stream);
				asyncWrite.DoCallback ();
				asyncWrite = null;
			}
		}