public bool SendNextAsync(int bytesLimit) { if (m_headerBytes != null) { byte[] b = m_headerBytes; m_headerBytes = null; if (!m_context.SendAsyncStart(b, 0, b.Length)) { if (m_body != null) { m_body.Dispose(); m_body = null; } RawBuffer = null; Sent = true; return(false); } return(true); } bool sendRes; if (RawBuffer != null) { if (RawBufferLen > 0) { byte[] b = RawBuffer; int s = RawBufferStart; if (RawBufferLen > bytesLimit) { RawBufferLen -= bytesLimit; RawBufferStart += bytesLimit; if (RawBufferLen <= 0) { RawBuffer = null; } sendRes = m_context.SendAsyncStart(b, s, bytesLimit); } else { int l = RawBufferLen; RawBufferLen = 0; RawBuffer = null; sendRes = m_context.SendAsyncStart(b, s, l); } if (!sendRes) { RawBuffer = null; if (m_body != null) { m_body.Dispose(); m_body = null; } Sent = true; return(false); } return(true); } else { RawBuffer = null; } } if (m_body != null) { if (m_body.Length != 0) { MemoryStream mb = m_body as MemoryStream; RawBuffer = mb.GetBuffer(); RawBufferStart = 0; // must be a internal buffer, or starting at 0 RawBufferLen = (int)mb.Length; m_body.Dispose(); m_body = null; if (RawBufferLen > 0) { byte[] b = RawBuffer; int s = RawBufferStart; if (RawBufferLen > bytesLimit) { RawBufferLen -= bytesLimit; RawBufferStart += bytesLimit; if (RawBufferLen <= 0) { RawBuffer = null; } sendRes = m_context.SendAsyncStart(b, s, bytesLimit); } else { int l = RawBufferLen; sendRes = m_context.SendAsyncStart(b, s, l); RawBufferLen = 0; RawBuffer = null; } if (!sendRes) { RawBuffer = null; Sent = true; return(false); } return(true); } else { RawBuffer = null; } } else { m_body.Dispose(); m_body = null; } } Sent = true; m_context.EndSendResponse(requestID, Connection); return(false); }