private void MoveNext() { if (step == 0) { } else if (step == 1) { goto STEP1; } else { throw new Exception(); } //while (pos < bs.Len) { WHILE: try { if (!(pos < bs.Len)) { goto EWHILE; } awaitable = myStream.ReadAsyncR(bs.Sub(pos)); step = 1; if (awaitable.IsCompleted) { goto STEP1; } awaitable.UnsafeOnCompleted(_moveNext); } catch (Exception e) { ResetState(); SetException(e); return; } return; STEP1: try { var read = awaitable.GetResult(); if (read == 0) { throw new DisconnectedException($"unexpected EOF while ReadFull() (count={bs.Len}, pos={pos})"); } pos += read; } catch (Exception e) { ResetState(); SetException(e); return; } goto WHILE; //} EWHILE: ResetState(); SetResult(VoidType.Void); return; }
private async Task readRequest() { var buf = BufferPool.GlobalGet(MaxRequestLength); var cur = 0; var gotLF = 0; while (true) { if (cur + 2 >= MaxRequestLength) { throw new Exception("request length > MaxRequestLength"); } var read = await myStream.ReadAsyncR(new BytesSegment(buf, cur, 2 - gotLF)).CAF(); if (read == 0) { throw new DisconnectedException("unexpected EOF"); } var parsingCur = cur; cur += read; while (parsingCur < cur) { var ch = buf[parsingCur++]; if (ch == '\n') { if (gotLF++ == 1) { goto DONE; } } else if (ch == '\r') { continue; } else { gotLF = 0; } } } DONE: var len = cur; RawRequestBytesLength = len; RawRequest = NaiveUtils.UTF8Encoding.GetString(buf, 0, len); BufferPool.GlobalPut(buf); }