func readPack(conn net.Conn, buf []byte) (string, error) {
var packet string
for {
n, err := conn.Read(buf)
if err != nil {
return "", fmt.Errorf("%w: failed read: %s", ErrConn, err)
}
packet += string(buf[:n])
if len(packet) > len(buf) {
return "", fmt.Errorf("%w: too long input: %d", ErrAMI, len(packet))
}
if strings.HasSuffix(packet, "\r\n\r\n") {
return packet, nil
}
}
}
In this fragment if AMI event is larger than buf, you'll get "too long input" error.
In my case AMI messages are going continuously and often conn.Read(buf) reads the whole AMI message together with the beginning of the next AMI message, so there is no "\r\n\r\n" in the end of packet value and finally function errors with "too long input" in next loop.
In this fragment if AMI event is larger than buf, you'll get "too long input" error.
In my case AMI messages are going continuously and often
conn.Read(buf)reads the whole AMI message together with the beginning of the next AMI message, so there is no "\r\n\r\n" in the end of packet value and finally function errors with "too long input" in next loop.