package sshtun type handshakePerLineReader struct { buf []byte off int cb func(line string) } func newHandshakePerLineReader(cb func(string)) func([]byte) { if cb == nil { return nil } lr := &handshakePerLineReader{cb: cb, buf: make([]byte, 1024)} return lr.packet } func (h *handshakePerLineReader) packet(p []byte) { for _, char := range p { if (char == 10 || char == 13) && len(h.buf) > 0 { h.cb(string(h.buf[:h.off])) h.off = 0 } if cap(h.buf) <= (h.off + 1) { newBuf := make([]byte, cap(h.buf)+256) copy(newBuf, h.buf) h.buf = newBuf } h.buf[h.off] = char h.off++ } }