this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

tty: correctly handle partial reads

+13 -1
+13 -1
src/Tty.zig
··· 144 144 145 145 // initialize the read buffer 146 146 var buf: [1024]u8 = undefined; 147 + var read_start: usize = 0; 147 148 // read loop 148 149 while (!self.should_quit) { 149 - const n = try posix.read(self.fd, &buf); 150 + const n = try posix.read(self.fd, buf[read_start..]); 150 151 var start: usize = 0; 151 152 while (start < n) { 152 153 const result = try parser.parse(buf[start..n], paste_allocator); 154 + if (result.n == 0) { 155 + // copy the read to the beginning. We don't use memcpy because 156 + // this could be overlapping, and it's also rare 157 + const initial_start = start; 158 + while (start < n) : (start += 1) { 159 + buf[start - initial_start] = buf[start]; 160 + } 161 + read_start = start - initial_start + 1; 162 + continue; 163 + } 164 + read_start = 0; 153 165 start += result.n; 154 166 // TODO: if we get 0 byte read, copy the remaining bytes to the 155 167 // beginning of the buffer and read mmore? this should only happen