+2003-06-12 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * HttpWebRequest.cs: use InternalClose when we are not going to send the
+ rest of the request stream because of an error after sending the
+ headers.
+
+ * WebConnection.cs: check for completion after setting the response.
+ Enable reading in NextRead.
+
+ * WebConnectionStream.cs: re-fixed the count for partially buffered
+ reads. If the network stream returns 0 bytes, we're done.
+
2003-06-11 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* WebClient.cs: implemented UploadFile. Fixed SetupRequest to set the
}
if (nread == 0) {
- Console.WriteLine ("nread == 0");
+ Console.WriteLine ("nread == 0: may be the connection was closed?");
+ cnc.dataAvailable.Set ();
return;
}
stream.ReadBuffer = cnc.buffer;
stream.ReadBufferOffset = pos;
stream.ReadBufferSize = nread;
- stream.CheckComplete ();
} else if (cnc.chunkStream == null) {
cnc.chunkStream = new ChunkStream (cnc.buffer, pos, nread, data.Headers);
} else {
cnc.prevStream = stream;
data.stream = stream;
data.request.SetResponseData (data);
+ stream.CheckComplete ();
}
static void InitRead (object state)
prevStream.ReadAll ();
prevStream = null;
}
-
+
if (!busy) {
busy = true;
Monitor.Exit (this);
Close ();
}
+ busy = false;
+ dataAvailable.Set ();
+
if (queue.Count > 0) {
HttpWebRequest request = (HttpWebRequest) queue [0];
queue.RemoveAt (0);
Monitor.Exit (this);
SendRequest (request);
} else {
- busy = false;
Monitor.Exit (this);
}
}
MemoryStream writeBuffer;
bool requestWritten;
byte [] headers;
+ bool disposed;
public WebConnectionStream (WebConnection cnc)
{
readBufferOffset += copy;
offset += copy;
size -= copy;
+ totalRead += copy;
if (size == 0 || totalRead >= contentLength) {
- totalRead += copy;
result.SetCompleted (true, copy);
result.DoCallback ();
return result;
{
WebAsyncResult result = (WebAsyncResult) r;
- int nbytes = -1;
- if (result.IsCompleted) {
- nbytes = result.NBytes;
- } else {
- nbytes = cnc.EndRead (result.InnerAsyncResult);
+ if (!result.IsCompleted) {
+ int nbytes = cnc.EndRead (result.InnerAsyncResult);
lock (this) {
pendingReads--;
if (pendingReads == 0)
pending.Set ();
}
- nbytes += result.NBytes; // partially filled from the read buffer
- result.SetCompleted (false, nbytes);
+ result.SetCompleted (false, nbytes + result.NBytes);
totalRead += nbytes;
+ if (nbytes == 0)
+ contentLength = totalRead;
}
if (totalRead >= contentLength && !nextReadCalled) {
cnc.NextRead ();
}
- return nbytes;
+ return result.NBytes;
}
public override IAsyncResult BeginWrite (byte [] buffer, int offset, int size,
cnc.dataAvailable.Set ();
}
+ internal void InternalClose ()
+ {
+ disposed = true;
+ }
+
public override void Close ()
{
- if (!allowBuffering)
+ if (isRead || !allowBuffering || disposed)
return;
- // may be ReadAll is isRead?
+ disposed = true;
+
long length = request.ContentLength;
if (length != -1 && length > writeBuffer.Length)
throw new IOException ("Cannot close the stream until all bytes are written");