private async Task FirstWriteToInjectScriptSocketAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { try { await _injectScriptSocket.WriteToRequestAsync(buffer, offset, count); Task <int> statusCodeTask = _injectScriptSocket.GetResponseStatusCode(); int statusCode = await TaskHelpers.WaitWithTimeout( statusCodeTask, timeout : TimeSpan.FromMilliseconds(1000), resultIfTimedOut : 504 /*Gateway Timeout*/); if (statusCode == 200) { return; } if (statusCode == 504) { ScriptInjectionTimedOut = true; } } catch { // Fall through to error case } // If the initial send fails, we can switch to passthrough mode // and retry this write. Browser Link won't work, but at least // the page will be returned to the browser. CloseInjectScriptSocketAndBecomePassthrough(); await WriteAsync(buffer, offset, count, cancellationToken); }
async Task <int> IHttpSocketAdapter.GetResponseStatusCode() { IHttpSocketAdapter socket = await GetConnectedSocketAsync(); return(await socket.GetResponseStatusCode()); }