From 95fb0ade3f0ffcd14596ec97605a1f19e9067938 Mon Sep 17 00:00:00 2001 From: Nick Stevens Date: Wed, 5 Apr 2017 06:56:51 -0500 Subject: [PATCH] Use automatic port for UDP send Use an automatically-assigned free UDP port in the ephemeral port range for sending by default. Since none of the DataDog metrics require two-way communication, the assigned port number does not need to be remembered/exposed. Signed-off-by: Nick Stevens --- README.md | 4 ++-- src/lib.rs | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 33693431..db2a2474 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Build an options struct and create a client: ```rust use dogstatsd::{Client, Options}; -// Binds to a udp socket on 127.0.0.1:8126 for transmitting, and sends to -// 127.0.0.1:8125, the default dogstatsd address. +// Binds to a udp socket on an available ephemeral port on 127.0.0.1 for +// transmitting, and sends to 127.0.0.1:8125, the default dogstatsd address. let default_options = Options::default(); let default_client = Client::new(default_options); diff --git a/src/lib.rs b/src/lib.rs index 8dee14f4..a0c1aa30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,9 @@ //! ``` //! use dogstatsd::{Client, Options}; //! -//! // Binds to a udp socket on 127.0.0.1:8126 for transmitting, and sends to -//! // 127.0.0.1:8125, the default dogstatsd address. +//! // Binds to a udp socket on an available ephemeral port on 127.0.0.1 for +//! // transmitting, and sends to 127.0.0.1:8125, the default dogstatsd +//! // address. //! let default_options = Options::default(); //! let default_client = Client::new(default_options); //! @@ -97,7 +98,7 @@ impl Options { /// /// assert_eq!( /// Options { - /// from_addr: "127.0.0.1:8126".into(), + /// from_addr: "127.0.0.1:0".into(), /// to_addr: "127.0.0.1:8125".into(), /// namespace: String::new(), /// }, @@ -106,7 +107,7 @@ impl Options { /// ``` pub fn default() -> Self { Options { - from_addr: "127.0.0.1:8126".into(), + from_addr: "127.0.0.1:0".into(), to_addr: "127.0.0.1:8125".into(), namespace: String::new(), } @@ -308,7 +309,7 @@ mod tests { fn test_options_default() { let options = Options::default(); let expected_options = Options { - from_addr: "127.0.0.1:8126".into(), + from_addr: "127.0.0.1:0".into(), to_addr: "127.0.0.1:8125".into(), namespace: String::new(), }; @@ -320,7 +321,7 @@ mod tests { fn test_new() { let client = Client::new(Options::default()); let expected_client = Client { - from_addr: "127.0.0.1:8126".into(), + from_addr: "127.0.0.1:0".into(), to_addr: "127.0.0.1:8125".into(), namespace: String::new(), };