()
| 97 | } |
| 98 | |
| 99 | public void RunLoop() |
| 100 | { |
| 101 | var lineRe = new Regex("^([^:]*):\\s*(.*)$", RegexOptions.Compiled); |
| 102 | |
| 103 | while (true) |
| 104 | { |
| 105 | Dictionary<string, string> headers = new Dictionary<string, string>(); |
| 106 | while (true) |
| 107 | { |
| 108 | var line = InputReader.ReadLine(); |
| 109 | if (line == null && InputReader.EndOfStream) |
| 110 | { |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | if (line.Length == 0) |
| 115 | { |
| 116 | break; |
| 117 | } |
| 118 | |
| 119 | var matches = lineRe.Match(line); |
| 120 | if (!matches.Success) |
| 121 | { |
| 122 | throw new InvalidDataException($"Malformed header line: {line}"); |
| 123 | } |
| 124 | |
| 125 | headers.Add(matches.Groups[1].Value, matches.Groups[2].Value); |
| 126 | if (matches.Groups[1].Value != "Content-Length") |
| 127 | { |
| 128 | throw new InvalidDataException($"{matches.Groups[1].Value}={matches.Groups[2].Value}"); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | if (headers.Count == 0) throw new InvalidDataException("Empty headers."); |
| 133 | |
| 134 | var length = Int32.Parse(headers["Content-Length"]); |
| 135 | var payload = new char[length]; |
| 136 | var read = InputReader.Read(payload, 0, length); |
| 137 | if (read != length) |
| 138 | { |
| 139 | throw new InvalidDataException($"Could not read {length} bytes of payload (got {read})"); |
| 140 | } |
| 141 | |
| 142 | ProcessPayload(payload); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | public void Send(DAPMessage message) |
| 147 | { |
no test coverage detected