aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/libpq-int.h
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2016-11-03 09:25:20 -0400
committerRobert Haas <rhaas@postgresql.org>2016-11-03 09:25:20 -0400
commit274bb2b3857cc987cfa21d14775cae9b0dababa5 (patch)
tree488b5fd46e2cb4acdab7fb2dd30c4e4d1d4bb7d1 /src/interfaces/libpq/libpq-int.h
parent770671062f130a830aa89100c9aa2d26f8d4bf32 (diff)
downloadpostgresql-274bb2b3857cc987cfa21d14775cae9b0dababa5.tar.gz
postgresql-274bb2b3857cc987cfa21d14775cae9b0dababa5.zip
libpq: Allow connection strings and URIs to specify multiple hosts.
It's also possible to specify a separate port for each host. Previously, we'd loop over every address returned by looking up the host name; now, we'll try every address for every host name. Patch by me. Victor Wagner wrote an earlier patch for this feature, which I read, but I didn't use any of his code. Review by Mithun Cy.
Diffstat (limited to 'src/interfaces/libpq/libpq-int.h')
-rw-r--r--src/interfaces/libpq/libpq-int.h41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 7007692fb10..854ec89924b 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -292,6 +292,30 @@ typedef struct pgDataValue
const char *value; /* data value, without zero-termination */
} PGdataValue;
+typedef enum pg_conn_host_type
+{
+ CHT_HOST_NAME,
+ CHT_HOST_ADDRESS,
+ CHT_UNIX_SOCKET
+} pg_conn_host_type;
+
+/*
+ * pg_conn_host stores all information about one of possibly several hosts
+ * mentioned in the connection string. Derived by splitting the pghost
+ * on the comma character and then parsing each segment.
+ */
+typedef struct pg_conn_host
+{
+ char *host; /* host name or address, or socket path */
+ pg_conn_host_type type; /* type of host */
+ char *port; /* port number for this host; if not NULL,
+ * overrrides the PGConn's pgport */
+ char *password; /* password for this host, read from the
+ * password file. only set if the PGconn's
+ * pgpass field is NULL. */
+ struct addrinfo *addrlist; /* list of possible backend addresses */
+} pg_conn_host;
+
/*
* PGconn stores all the state data associated with a single connection
* to a backend.
@@ -299,13 +323,15 @@ typedef struct pgDataValue
struct pg_conn
{
/* Saved values of connection options */
- char *pghost; /* the machine on which the server is running */
+ char *pghost; /* the machine on which the server is running,
+ * or a path to a UNIX-domain socket, or a
+ * comma-separated list of machines and/or
+ * paths, optionally with port suffixes; if
+ * NULL, use DEFAULT_PGSOCKET_DIR */
char *pghostaddr; /* the numeric IP address of the machine on
* which the server is running. Takes
* precedence over above. */
char *pgport; /* the server's communication port number */
- char *pgunixsocket; /* the directory of the server's Unix-domain
- * socket; if NULL, use DEFAULT_PGSOCKET_DIR */
char *pgtty; /* tty on which the backend messages is
* displayed (OBSOLETE, NOT USED) */
char *connect_timeout; /* connection timeout (numeric string) */
@@ -363,6 +389,11 @@ struct pg_conn
PGnotify *notifyHead; /* oldest unreported Notify msg */
PGnotify *notifyTail; /* newest unreported Notify msg */
+ /* Support for multiple hosts in connection string */
+ int nconnhost; /* # of possible hosts */
+ int whichhost; /* host we're currently considering */
+ pg_conn_host *connhost; /* details about each possible host */
+
/* Connection data */
pgsocket sock; /* FD for socket, PGINVALID_SOCKET if
* unconnected */
@@ -378,9 +409,7 @@ struct pg_conn
bool sigpipe_flag; /* can we mask SIGPIPE via MSG_NOSIGNAL? */
/* Transient state needed while establishing connection */
- struct addrinfo *addrlist; /* list of possible backend addresses */
- struct addrinfo *addr_cur; /* the one currently being tried */
- int addrlist_family; /* needed to know how to free addrlist */
+ struct addrinfo *addr_cur; /* backend address currently being tried */
PGSetenvStatusType setenv_state; /* for 2.0 protocol only */
const PQEnvironmentOption *next_eo;
bool send_appname; /* okay to send application_name? */