summaryrefslogtreecommitdiff
path: root/client/client_priv.h
diff options
context:
space:
mode:
Diffstat (limited to 'client/client_priv.h')
-rw-r--r--client/client_priv.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/client/client_priv.h b/client/client_priv.h
index 64818d2ab8d..7178c1b7ef0 100644
--- a/client/client_priv.h
+++ b/client/client_priv.h
@@ -136,3 +136,61 @@ enum options_client
Name of the sys schema database.
*/
#define SYS_SCHEMA_DB_NAME "sys"
+
+/**
+ The --socket CLI option has different meanings
+ across different operating systems.
+ */
+#ifndef __WIN__
+#define SOCKET_PROTOCOL_TO_FORCE MYSQL_PROTOCOL_SOCKET
+#else
+#define SOCKET_PROTOCOL_TO_FORCE MYSQL_PROTOCOL_PIPE
+#endif
+
+/**
+ Utility function to implicitly change the connection protocol to a
+ consistent value given the command line arguments. Additionally,
+ warns the user that the protocol has been changed.
+
+ Arguments:
+ @param [in] host Name of the host to connect to
+ @param [in, out] opt_protocol Location of the protocol option
+ variable to update
+ @param [in] new_protocol New protocol to force
+*/
+static inline void warn_protocol_override(char *host,
+ uint *opt_protocol,
+ uint new_protocol)
+{
+ DBUG_ASSERT(new_protocol == MYSQL_PROTOCOL_TCP
+ || new_protocol == SOCKET_PROTOCOL_TO_FORCE);
+
+
+ if ((host == NULL
+ || strncmp(host, LOCAL_HOST, sizeof(LOCAL_HOST)-1) == 0))
+ {
+ const char *protocol_name;
+
+ if (*opt_protocol == MYSQL_PROTOCOL_DEFAULT
+#ifndef __WIN__
+ && new_protocol == MYSQL_PROTOCOL_SOCKET
+#else
+ && new_protocol == MYSQL_PROTOCOL_TCP
+#endif
+ )
+ {
+ /* This is already the default behavior, do nothing */
+ return;
+ }
+
+ protocol_name= sql_protocol_typelib.type_names[new_protocol-1];
+
+ fprintf(stderr, "%s %s %s\n",
+ "WARNING: Forcing protocol to ",
+ protocol_name,
+ " due to option specification. "
+ "Please explicitly state intended protocol.");
+
+ *opt_protocol = new_protocol;
+ }
+}