func (a *Aggregator) readLogsFromConn(conn net.Conn) { defer conn.Close() connDone := make(chan struct{}) defer close(connDone) go func() { select { case <-connDone: case <-a.shutdown: conn.Close() } }() s := bufio.NewScanner(conn) s.Split(rfc6587.Split) for s.Scan() { msgBytes := s.Bytes() // slice in msgBytes could get modified on next Scan(), need to copy it msgCopy := make([]byte, len(msgBytes)) copy(msgCopy, msgBytes) msg, err := rfc5424.Parse(msgCopy) if err != nil { log15.Error("rfc5424 parse error", "err", err) } else { a.msgc <- msg } } }
func (a *Aggregator) readLogsFromConn(conn net.Conn) { defer conn.Close() connDone := make(chan struct{}) defer close(connDone) go func() { select { case <-connDone: case <-a.shutdown: conn.Close() } }() s := bufio.NewScanner(conn) s.Split(rfc6587.Split) for s.Scan() { msgBytes := s.Bytes() // slice in msgBytes could get modified on next Scan(), need to copy it msgCopy := make([]byte, len(msgBytes)) copy(msgCopy, msgBytes) msg, err := rfc5424.Parse(msgCopy) if err != nil { log15.Error("rfc5424 parse error", "err", err) continue } a.getOrInitializeBuffer(string(msg.AppName)).Add(msg) if afterMessage != nil { afterMessage() } } }
func ParseMessage(data []byte) (*rfc5424.Message, *HostCursor, error) { msg, err := rfc5424.Parse(data) if err != nil { return nil, nil, err } c, err := ParseHostCursor(msg) return msg, c, err }
func runServer(l net.Listener, h func(*rfc5424.Message)) { for { conn, err := l.Accept() if err != nil { return } go func() { s := bufio.NewScanner(conn) s.Split(rfc6587.Split) for s.Scan() { msg, err := rfc5424.Parse(s.Bytes()) if err != nil { conn.Close() return } h(msg) } conn.Close() }() } }