From cbde04fc7c1d0237af2faad74db7bbb1fd97c89d Mon Sep 17 00:00:00 2001 From: root <> Date: Sat, 17 May 2025 08:15:07 +0000 Subject: [PATCH] client__pollin diagram --- client-pollin.txt | 50 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client-pollin.txt diff --git a/client-pollin.txt b/client-pollin.txt new file mode 100644 index 0000000..2e0f6b1 --- /dev/null +++ b/client-pollin.txt @@ -0,0 +1,50 @@ +client buffer + +##########++++++++A++++++A+++A++.......... +^ ^ ^ ^ ^ ^ ^ +| | | | | | | +| | | | | | +-- end of buffer +| | | | | | +| | | | | +-- end of read(2) bytes +| | | | | +| | +-- newlines +| | +| +-- start of line scanning +| ++-- start of line + + +# original idea + +- consume many lines in client__pollin +- problem: in the echo server case, we want to write each line but a call to + write(2) may block, so we can't do line processing in client__pollin +- solution: process lines in client__pollout + +i = scan_start +while i < buffer_end: + byte = mem[i] + i += 1 + if byte == '\n': + handle(line_start, i - line_start) + line_start = i + scan_start = i + +if line_start + read(2)_length >= buffer_end: + out_of_memory() + return + +i = line_start +while i < line_start + read(2)_length: + mem[i - line_start + buffer_start] = mem[i] + i += 1 + + +# better idea + +in pollin handler, just read once +indicate to the caller: +- we read a complete line (ie 0x0a is present) +- we read an incomplete non-empty line +- we read nothing (EOF) +- error from read(2)