mut buf := []byte{len: 1024}
if nbytes := sock.read(mut buf) {
println('irc $sock $nbytes bytes read')
c <- string(buf)
} else {
println('irc err')
mut buf := []byte{len: 128}
mut bufidx := 0
for {
if nbytes := sock.read(mut buf[bufidx..]) {
println("irc sock.read buf $bufidx .. $buf.len -> $nbytes bytes read")
bufidx_stop := bufidx+nbytes
if idx := idx_of(buf[bufidx..bufidx_stop]) {
println("irc middle checking $bufidx .. $bufidx_stop => newline at $idx")
bufidx_nl := bufidx + idx
bufidx_nlstop := bufidx_nl - 1
str := string(buf[bufidx..bufidx_nlstop].clone())
println("irc middle sending $bufidx .. $bufidx_nlstop len ($str.len)$str ")
c <- str
save_count := bufidx_stop - bufidx_nlstop
println("post channel send, bufidx_stop $bufidx_stop bufidx_nlstop $bufidx_nlstop save_count $save_count")
if save_count > 1 {
bufidx = bufidx_nlstop
} else {
bufidx = 0
}
} else {
println('partial: no newlines in $nbytes')
bufidx = nbytes
}
} else {
println('irc sock read err bufidx $bufidx ..')
}