if nbytes := sock.read(mut buf[bufidx..]) {
// println('irc sock.read buf $bufidx .. $buf.len -> $nbytes bytes read')
buflen_stop := bufidx + nbytes
for {
if idx := idx_of(buf[bufidx..buflen_stop]) {
// println('irc middle checking $bufidx .. $buflen_stop => newline at $idx')
bufidx_nl := bufidx + idx
str := string(buf[bufidx..bufidx_nl].clone())
// println('irc middle sending $bufidx .. $bufidx_nl len ($str.len)$str ')
c <- str
bufidx_nlpost := bufidx_nl + idx_of_not_newline(buf[bufidx_nl..])
// println('post channel send, buflen_stop $buflen_stop bufidx_nlpost $bufidx_nlpost')
if buflen_stop == bufidx_nlpost {
// println('bufidx = 0. peeled $buflen_stop bytes')
break // read more
} else {
// println('bufidx moved to bufidx_nlpost $bufidx_nlpost buflen_stop $buflen_stop save (${buflen_stop -
// bufidx_nlpost})')
}
bufidx = bufidx_nlpost
} else {
println('partial: no newlines in $nbytes')
break // read more
}
}