/// <summary> /// Call this method to signal the host that all the content for filtering /// has been sent, and then wait for the host to return the filtered content. /// </summary> /// <returns>A task that completes when the host has returned the filtered contet.</returns> public async Task WaitForFilterComplete() { if (SentContentToFilter) { await _injectScriptSocket.CompleteRequest(); await _injectScriptSocket.WaitForResponseComplete(); } CloseInjectScriptSocketAndBecomePassthrough(); }
async Task IHttpSocketAdapter.CompleteRequest() { // If a connection hasn't been created yet, no data has been sent. // If there's no response listener, no data will be received. // If both of those are true, it's a safe bet that the connection is unnecessary. if (_connectedSocketTask == null && _responseHandler == null) { return; } else { IHttpSocketAdapter socket = await GetConnectedSocketAsync(); await socket.CompleteRequest(); } }
/// <remarks> /// This function is the pump that pushes data from the buffers into an /// HTTP connection. It asynchronously waits on data, then asynchronously /// waits while the data is sent, then waits on more data, etc. /// </remarks> private static async void SendDataFromBuffersAsync(RevolvingBuffers <byte> buffer, IHttpSocketAdapter adapter) { while (true) { ArraySegment <byte> bufferToSend = await buffer.GetBufferedDataAsync(); if (bufferToSend.Count == 0) { break; } await adapter.WriteToRequestAsync(bufferToSend.Array, bufferToSend.Offset, bufferToSend.Count); } await adapter.CompleteRequest(); adapter.Dispose(); }