2015-10-08 16:45:23 +00:00
|
|
|
package subscriber
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
|
2016-02-10 17:26:18 +00:00
|
|
|
"github.com/influxdata/influxdb/cluster"
|
2015-10-08 16:45:23 +00:00
|
|
|
)
|
|
|
|
|
2015-11-18 09:32:39 +00:00
|
|
|
// UDP supports writing points over UDP using the line protocol.
|
2015-10-08 16:45:23 +00:00
|
|
|
type UDP struct {
|
|
|
|
addr string
|
|
|
|
}
|
|
|
|
|
2015-11-18 09:32:39 +00:00
|
|
|
// NewUDP returns a new UDP listener with default options.
|
2015-10-08 16:45:23 +00:00
|
|
|
func NewUDP(addr string) *UDP {
|
|
|
|
return &UDP{addr: addr}
|
|
|
|
}
|
|
|
|
|
2015-11-18 09:32:39 +00:00
|
|
|
// WritePoints writes points over UDP transport.
|
2015-10-08 16:45:23 +00:00
|
|
|
func (u *UDP) WritePoints(p *cluster.WritePointsRequest) (err error) {
|
|
|
|
var addr *net.UDPAddr
|
|
|
|
var con *net.UDPConn
|
|
|
|
addr, err = net.ResolveUDPAddr("udp", u.addr)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
con, err = net.DialUDP("udp", nil, addr)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer con.Close()
|
|
|
|
|
|
|
|
for _, p := range p.Points {
|
|
|
|
_, err = con.Write([]byte(p.String()))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|