Ejemplo n.º 1
0
func (f *InForward) handleConn(conn net.Conn) {
	defer func() {
		f.monitorCh <- &ReceiverStat{
			Connections: -1,
		}
	}()
	for {
		recordSets, err := fluent.DecodeEntries(conn)
		if err == io.EOF {
			conn.Close()
			return
		} else if err != nil {
			log.Println("[error] Decode entries failed", err, conn.LocalAddr())
			conn.Close()
			return
		}
		m := int64(0)
		d := int64(0)
		for _, recordSet := range recordSets {
			rs := &recordSet
			d += f.messageQueue.Enqueue(rs)
			m += int64(len(rs.Records))
		}
		f.monitorCh <- &ReceiverStat{
			Messages: m,
			Disposed: d,
			Buffered: int64(f.messageQueue.Len()),
		}
	}
}
Ejemplo n.º 2
0
func handleForwardConn(conn net.Conn) {
	defer conn.Close()
	for {
		recordSets, err := fluent.DecodeEntries(conn)
		if err == io.EOF {
			return
		} else if err != nil {
			log.Println("decode entries failed", err, conn.LocalAddr())
			return
		}
		for _, recordSet := range recordSets {
			atomic.AddInt64(&Counter, int64(len(recordSet.Records)))
			if DumpCh != nil {
				select {
				case DumpCh <- recordSet:
				default:
					log.Printf("[warn] %d records dropped for dump file. tag: %s", len(recordSet.Records), recordSet.Tag)
				}
			}
			for tag, channels := range MessageCh {
				if !matchTag(tag, recordSet.Tag) {
					continue
				}
				for _, ch := range channels {
					select {
					case ch <- recordSet:
					default:
						log.Printf("[warn] %d records dropped for http client.", len(recordSet.Records))
					}
				}
			}
		}
	}
}
Ejemplo n.º 3
0
func handleConn(conn net.Conn, counter *int64) {
	for {
		recordSets, err := fluent.DecodeEntries(conn)
		if err == io.EOF {
			conn.Close()
			return
		} else if err != nil {
			log.Println("decode entries failed", err, conn.LocalAddr())
			conn.Close()
			return
		}
		n := 0
		for _, recordSet := range recordSets {
			n += len(recordSet.Records)
			if !DEBUG {
				continue
			}
			for _, record := range recordSet.Records {
				if DEBUG {
					fmt.Println(record)
				}
			}
		}
		atomic.AddInt64(counter, int64(n))
	}
}
func handleConn(conn net.Conn, t *testing.T, counter *int64) {
	for {
		recordSets, err := fluent.DecodeEntries(conn)
		if err != nil {
			if err != io.EOF {
				log.Println("[error][mockServer] decode entries failed", err, conn.LocalAddr())
			}
			conn.Close()
			return
		}
		for _, recordSet := range recordSets {
			for _, record := range recordSet.Records {
				atomic.AddInt64(counter, int64(1))
				log.Println(record)
			}
		}
	}
}
Ejemplo n.º 5
0
func (f *InForward) handleConn(conn net.Conn, c *Context) {
	c.InputProcess.Add(1)
	defer c.InputProcess.Done()
	defer func() {
		f.monitorCh <- &ReceiverStat{
			Connections: -1,
		}
	}()

	for {
		select {
		case <-c.ControlCh:
			log.Println("shutdown in_forward connection", conn)
			return
		default:
		}
		recordSets, err := fluent.DecodeEntries(conn)
		if err == io.EOF {
			conn.Close()
			return
		} else if err != nil {
			log.Println("[error] Decode entries failed", err, conn.LocalAddr())
			conn.Close()
			return
		}
		m := int64(0)
		d := int64(0)
		for _, recordSet := range recordSets {
			rs := &recordSet
			d += f.messageQueue.Enqueue(rs)
			m += int64(len(rs.Records))
		}
		f.monitorCh <- &ReceiverStat{
			Messages: m,
			Disposed: d,
			Buffered: int64(f.messageQueue.Len()),
		}
	}
}