本文整理汇总了C#中System.Net.WebAsyncResult.DoCallback方法的典型用法代码示例。如果您正苦于以下问题:C# WebAsyncResult.DoCallback方法的具体用法?C# WebAsyncResult.DoCallback怎么用?C# WebAsyncResult.DoCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebAsyncResult
的用法示例。
在下文中一共展示了WebAsyncResult.DoCallback方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginRead
internal IAsyncResult BeginRead (HttpWebRequest request, byte [] buffer, int offset, int size, AsyncCallback cb, object state)
{
Stream s = null;
lock (this) {
if (Data.request != request)
throw new ObjectDisposedException (typeof (NetworkStream).FullName);
if (nstream == null)
return null;
s = nstream;
}
IAsyncResult result = null;
if (!chunkedRead || (!chunkStream.DataAvailable && chunkStream.WantMore)) {
try {
result = s.BeginRead (buffer, offset, size, cb, state);
cb = null;
} catch (Exception) {
HandleError (WebExceptionStatus.ReceiveFailure, null, "chunked BeginRead");
throw;
}
}
if (chunkedRead) {
WebAsyncResult wr = new WebAsyncResult (cb, state, buffer, offset, size);
wr.InnerAsyncResult = result;
if (result == null) {
// Will be completed from the data in ChunkStream
wr.SetCompleted (true, (Exception) null);
wr.DoCallback ();
}
return wr;
}
return result;
}
示例2: BeginGetRequestStream
public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state)
{
if (Aborted)
throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled);
bool send = !(method == "GET" || method == "CONNECT" || method == "HEAD" ||
method == "TRACE");
if (method == null || !send)
throw new ProtocolViolationException ("Cannot send data when method is: " + method);
if (contentLength == -1 && !sendChunked && !allowBuffering && KeepAlive)
throw new ProtocolViolationException ("Content-Length not set");
string transferEncoding = TransferEncoding;
if (!sendChunked && transferEncoding != null && transferEncoding.Trim () != "")
throw new ProtocolViolationException ("SendChunked should be true.");
lock (locker)
{
if (getResponseCalled)
throw new InvalidOperationException ("The operation cannot be performed once the request has been submitted.");
if (asyncWrite != null) {
throw new InvalidOperationException ("Cannot re-call start of asynchronous " +
"method while a previous call is still in progress.");
}
asyncWrite = new WebAsyncResult (this, callback, state);
initialMethod = method;
if (haveRequest) {
if (writeStream != null) {
asyncWrite.SetCompleted (true, writeStream);
asyncWrite.DoCallback ();
return asyncWrite;
}
}
gotRequestStream = true;
WebAsyncResult result = asyncWrite;
if (!requestSent) {
requestSent = true;
redirects = 0;
servicePoint = GetServicePoint ();
abortHandler = servicePoint.SendRequest (this, connectionGroup);
}
return result;
}
}
示例3: GetResponseAsyncCB2
void GetResponseAsyncCB2 (WebAsyncResult aread)
{
if (haveResponse) {
Exception saved = saved_exc;
if (webResponse != null) {
Monitor.Exit (locker);
if (saved == null) {
aread.SetCompleted (true, webResponse);
} else {
aread.SetCompleted (true, saved);
}
aread.DoCallback ();
return;
} else if (saved != null) {
Monitor.Exit (locker);
aread.SetCompleted (true, saved);
aread.DoCallback ();
return;
}
}
if (!requestSent) {
requestSent = true;
redirects = 0;
servicePoint = GetServicePoint ();
abortHandler = servicePoint.SendRequest (this, connectionGroup);
}
Monitor.Exit (locker);
}
示例4: BeginWrite
public override IAsyncResult BeginWrite (byte [] buffer, int offset, int size,
AsyncCallback cb, object state)
{
if (request.Aborted)
throw new WebException ("The request was canceled.", WebExceptionStatus.RequestCanceled);
if (isRead)
throw new NotSupportedException ("this stream does not allow writing");
if (buffer == null)
throw new ArgumentNullException ("buffer");
int length = buffer.Length;
if (offset < 0 || length < offset)
throw new ArgumentOutOfRangeException ("offset");
if (size < 0 || (length - offset) < size)
throw new ArgumentOutOfRangeException ("size");
if (sendChunked) {
lock (locker) {
pendingWrites++;
pending.Reset ();
}
}
WebAsyncResult result = new WebAsyncResult (cb, state);
AsyncCallback callback = new AsyncCallback (WriteAsyncCB);
if (sendChunked) {
requestWritten = true;
string cSize = String.Format ("{0:X}\r\n", size);
byte[] head = Encoding.ASCII.GetBytes (cSize);
int chunkSize = 2 + size + head.Length;
byte[] newBuffer = new byte [chunkSize];
Buffer.BlockCopy (head, 0, newBuffer, 0, head.Length);
Buffer.BlockCopy (buffer, offset, newBuffer, head.Length, size);
Buffer.BlockCopy (crlf, 0, newBuffer, head.Length + size, crlf.Length);
if (allowBuffering) {
if (writeBuffer == null)
writeBuffer = new MemoryStream ();
writeBuffer.Write (buffer, offset, size);
totalWritten += size;
}
buffer = newBuffer;
offset = 0;
size = chunkSize;
} else {
CheckWriteOverflow (request.ContentLength, totalWritten, size);
if (allowBuffering) {
if (writeBuffer == null)
writeBuffer = new MemoryStream ();
writeBuffer.Write (buffer, offset, size);
totalWritten += size;
if (request.ContentLength <= 0 || totalWritten < request.ContentLength) {
result.SetCompleted (true, 0);
result.DoCallback ();
return result;
}
result.AsyncWriteAll = true;
requestWritten = true;
buffer = writeBuffer.GetBuffer ();
offset = 0;
size = (int)totalWritten;
}
}
try {
result.InnerAsyncResult = cnc.BeginWrite (request, buffer, offset, size, callback, result);
if (result.InnerAsyncResult == null) {
if (!result.IsCompleted)
result.SetCompleted (true, 0);
result.DoCallback ();
}
} catch (Exception) {
if (!IgnoreIOErrors)
throw;
result.SetCompleted (true, 0);
result.DoCallback ();
}
totalWritten += size;
return result;
}
示例5: BeginRead
public override IAsyncResult BeginRead (byte [] buffer, int offset, int size,
AsyncCallback cb, object state)
{
if (!isRead)
throw new NotSupportedException ("this stream does not allow reading");
if (buffer == null)
throw new ArgumentNullException ("buffer");
int length = buffer.Length;
if (offset < 0 || length < offset)
throw new ArgumentOutOfRangeException ("offset");
if (size < 0 || (length - offset) < size)
throw new ArgumentOutOfRangeException ("size");
lock (locker) {
pendingReads++;
pending.Reset ();
}
WebAsyncResult result = new WebAsyncResult (cb, state, buffer, offset, size);
if (totalRead >= contentLength) {
result.SetCompleted (true, -1);
result.DoCallback ();
return result;
}
int remaining = readBufferSize - readBufferOffset;
if (remaining > 0) {
int copy = (remaining > size) ? size : remaining;
Buffer.BlockCopy (readBuffer, readBufferOffset, buffer, offset, copy);
readBufferOffset += copy;
offset += copy;
size -= copy;
totalRead += copy;
if (size == 0 || totalRead >= contentLength) {
result.SetCompleted (true, copy);
result.DoCallback ();
return result;
}
result.NBytes = copy;
}
if (cb != null)
cb = cb_wrapper;
if (contentLength != Int64.MaxValue && contentLength - totalRead < size)
size = (int)(contentLength - totalRead);
if (!read_eof) {
result.InnerAsyncResult = cnc.BeginRead (request, buffer, offset, size, cb, result);
} else {
result.SetCompleted (true, result.NBytes);
result.DoCallback ();
}
return result;
}
示例6: SetHeadersAsync
internal void SetHeadersAsync (byte[] buffer, WebAsyncResult result)
{
if (headersSent)
return;
headers = buffer;
long cl = request.ContentLength;
string method = request.Method;
bool no_writestream = (method == "GET" || method == "CONNECT" || method == "HEAD" ||
method == "TRACE");
bool webdav = (method == "PROPFIND" || method == "PROPPATCH" || method == "MKCOL" ||
method == "COPY" || method == "MOVE" || method == "LOCK" ||
method == "UNLOCK");
if (sendChunked || cl > -1 || no_writestream || webdav) {
headersSent = true;
try {
result.InnerAsyncResult = cnc.BeginWrite (request, headers, 0, headers.Length, new AsyncCallback(SetHeadersCB), result);
if (result.InnerAsyncResult == null) {
// when does BeginWrite return null? Is the case when the request is aborted?
if (!result.IsCompleted)
result.SetCompleted (true, 0);
result.DoCallback ();
}
} catch (Exception exc) {
result.SetCompleted (true, exc);
result.DoCallback ();
}
} else {
result.SetCompleted (true, 0);
result.DoCallback ();
}
}