Skip to content

Commit

Permalink
Merge pull request #39 from Sliide/master
Browse files Browse the repository at this point in the history
BufferedClient: Do not create a new UDP socket on every flush
  • Loading branch information
quipo authored Mar 3, 2017
2 parents 75b7afe + 01e1623 commit 39c3fe5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 0 additions & 5 deletions bufferedclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ func (sb *StatsdBuffer) flush() (err error) {
if n == 0 {
return nil
}
err = sb.statsd.CreateSocket()
if nil != err {
sb.Logger.Println("Error establishing UDP connection for sending statsd events:", err)
return err
}
if err := sb.statsd.SendEvents(sb.events); err != nil {
sb.Logger.Println(err)
return err
Expand Down
2 changes: 1 addition & 1 deletion bufferedclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestBufferedTotal(t *testing.T) {
hostname, err := os.Hostname()
expected["zz."+hostname] = 1

go doListenUDP(t, ln, ch, len(s))
go doListenUDP(t, ln, ch, 1)

err = buffered.CreateSocket()
if nil != err {
Expand Down
9 changes: 7 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,25 @@ func doListenUDP(t *testing.T, conn *net.UDPConn, ch chan string, n int) {
}

func doListenTCP(t *testing.T, conn net.Listener, ch chan string, n int) {
client, err := conn.Accept()
for {
client, err := conn.Accept()
if err != nil {
t.Fatal(err)
}

buf := make([]byte, 1024)
c, err := client.Read(buf)
if err != nil {
if err.Error() == "EOF" {
return
}
t.Fatal(err)
}

for _, s := range bytes.Split(buf[:c], []byte{'\n'}) {
ch <- string(s)
if len(s) > 0 {
ch <- string(s)
}
}
}
}
Expand Down

0 comments on commit 39c3fe5

Please sign in to comment.