-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I tried updating #123 with ~50 commits but the diff got too messy. Easier to just add the changes on a new commit.
- Loading branch information
1 parent
2a099d8
commit c30dfce
Showing
6 changed files
with
380 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package datadog | ||
|
||
import "net" | ||
|
||
type udpWriter struct { | ||
conn net.Conn | ||
} | ||
|
||
// newUDPWriter returns a pointer to a new newUDPWriter given a socket file path as addr. | ||
func newUDPWriter(addr string) (*udpWriter, error) { | ||
udpAddr, err := net.ResolveUDPAddr("udp", addr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
conn, err := net.DialUDP("udp", nil, udpAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &udpWriter{conn: conn}, nil | ||
|
||
} | ||
|
||
// Write data to the UDP connection | ||
func (w *udpWriter) Write(data []byte) (int, error) { | ||
return w.conn.Write(data) | ||
} | ||
|
||
func (w *udpWriter) Close() error { | ||
return w.conn.Close() | ||
} | ||
|
||
func (w *udpWriter) CalcBufferSize(sizehint int) (int, error) { | ||
f, err := w.conn.(*net.UDPConn).File() | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer f.Close() | ||
|
||
return bufSizeFromFD(f, sizehint) | ||
} |
Oops, something went wrong.