Skip to content

Commit d97bed6

Browse files
committed
also update postgres
1 parent 48874dc commit d97bed6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

postgres/src/config.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::connection::Connection;
66
use crate::Client;
77
use log::info;
88
use std::fmt;
9+
use std::net::IpAddr;
910
use std::path::Path;
1011
use std::str::FromStr;
1112
use std::sync::Arc;
@@ -39,6 +40,19 @@ use tokio_postgres::{Error, Socket};
3940
/// path to the directory containing Unix domain sockets. Otherwise, it is treated as a hostname. Multiple hosts
4041
/// can be specified, separated by commas. Each host will be tried in turn when connecting. Required if connecting
4142
/// with the `connect` method.
43+
/// * `hostaddr` - Numeric IP address of host to connect to. This should be in the standard IPv4 address format,
44+
/// e.g., 172.28.40.9. If your machine supports IPv6, you can also use those addresses.
45+
/// If this parameter is not specified, the value of `host` will be looked up to find the corresponding IP address,
46+
/// - or if host specifies an IP address, that value will be used directly.
47+
/// Using `hostaddr` allows the application to avoid a host name look-up, which might be important in applications
48+
/// with time constraints. However, a host name is required for verify-full SSL certificate verification.
49+
/// Specifically:
50+
/// * If `hostaddr` is specified without `host`, the value for `hostaddr` gives the server network address.
51+
/// The connection attempt will fail if the authentication method requires a host name;
52+
/// * If `host` is specified without `hostaddr`, a host name lookup occurs;
53+
/// * If both `host` and `hostaddr` are specified, the value for `hostaddr` gives the server network address.
54+
/// The value for `host` is ignored unless the authentication method requires it,
55+
/// in which case it will be used as the host name.
4256
/// * `port` - The port to connect to. Multiple ports can be specified, separated by commas. The number of ports must be
4357
/// either 1, in which case it will be used for all hosts, or the same as the number of hosts. Defaults to 5432 if
4458
/// omitted or the empty string.
@@ -67,6 +81,10 @@ use tokio_postgres::{Error, Socket};
6781
/// ```
6882
///
6983
/// ```not_rust
84+
/// host=host1,host2,host3 port=1234,,5678 hostaddr=127.0.0.1,127.0.0.2,127.0.0.3 user=postgres target_session_attrs=read-write
85+
/// ```
86+
///
87+
/// ```not_rust
7088
/// host=host1,host2,host3 port=1234,,5678 user=postgres target_session_attrs=read-write
7189
/// ```
7290
///
@@ -204,6 +222,7 @@ impl Config {
204222
///
205223
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
206224
/// systems, a host starting with a `/` is interpreted as a path to a directory containing Unix domain sockets.
225+
/// There must be either no hosts, or the same number of hosts as hostaddrs.
207226
pub fn host(&mut self, host: &str) -> &mut Config {
208227
self.config.host(host);
209228
self
@@ -214,6 +233,11 @@ impl Config {
214233
self.config.get_hosts()
215234
}
216235

236+
/// Gets the hostaddrs that have been added to the configuration with `hostaddr`.
237+
pub fn get_hostaddrs(&self) -> &[IpAddr] {
238+
self.config.get_hostaddrs()
239+
}
240+
217241
/// Adds a Unix socket host to the configuration.
218242
///
219243
/// Unlike `host`, this method allows non-UTF8 paths.
@@ -226,6 +250,15 @@ impl Config {
226250
self
227251
}
228252

253+
/// Adds a hostaddr to the configuration.
254+
///
255+
/// Multiple hostaddrs can be specified by calling this method multiple times, and each will be tried in order.
256+
/// There must be either no hostaddrs, or the same number of hostaddrs as hosts.
257+
pub fn hostaddr(&mut self, hostaddr: IpAddr) -> &mut Config {
258+
self.config.hostaddr(hostaddr);
259+
self
260+
}
261+
229262
/// Adds a port to the configuration.
230263
///
231264
/// Multiple ports can be specified by calling this method multiple times. There must either be no ports, in which

tokio-postgres/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl Config {
302302
///
303303
/// Multiple hosts can be specified by calling this method multiple times, and each will be tried in order. On Unix
304304
/// systems, a host starting with a `/` is interpreted as a path to a directory containing Unix domain sockets.
305+
/// There must be either no hosts, or the same number of hosts as hostaddrs.
305306
pub fn host(&mut self, host: &str) -> &mut Config {
306307
#[cfg(unix)]
307308
{

0 commit comments

Comments
 (0)