summaryrefslogtreecommitdiff
path: root/sql-common/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'sql-common/client.c')
-rw-r--r--sql-common/client.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index b66eee2a508..66c68e5952d 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -96,6 +96,7 @@ my_bool net_flush(NET *net);
#ifndef _WIN32
#include <errno.h>
#define SOCKET_ERROR -1
+#define INVALID_SOCKET -1
#endif
#ifdef __WIN__
@@ -264,7 +265,6 @@ HANDLE create_named_pipe(MYSQL *mysql, uint connect_timeout, char **arg_host,
char pipe_name[1024];
DWORD dwMode;
int i;
- my_bool testing_named_pipes=0;
char *host= *arg_host, *unix_socket= *arg_unix_socket;
if ( ! unix_socket || (unix_socket)[0] == 0x00)
@@ -375,7 +375,7 @@ HANDLE create_shared_memory(MYSQL *mysql,NET *net, uint connect_timeout)
char *shared_memory_base_name = mysql->options.shared_memory_base_name;
static const char *name_prefixes[] = {"","Global\\"};
const char *prefix;
- int i;
+ uint i;
/*
If this is NULL, somebody freed the MYSQL* options. mysql_close()
@@ -748,7 +748,7 @@ void free_old_query(MYSQL *mysql)
if (mysql->fields)
free_root(&mysql->field_alloc,MYF(0));
/* Assume rowlength < 8192 */
- init_alloc_root(&mysql->field_alloc, 8192, 0,
+ init_alloc_root(&mysql->field_alloc, "fields", 8192, 0,
MYF(mysql->options.use_thread_specific_memory ?
MY_THREAD_SPECIFIC : 0));
mysql->fields= 0;
@@ -923,13 +923,6 @@ static int cli_report_progress(MYSQL *mysql, char *pkt, uint length)
return 0;
}
-#ifdef __WIN__
-static my_bool is_NT(void)
-{
- char *os=getenv("OS");
- return (os && !strcmp(os, "Windows_NT")) ? 1 : 0;
-}
-#endif
/**************************************************************************
Shut down connection
@@ -1495,7 +1488,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
DBUG_RETURN(0);
}
/* Assume rowlength < 8192 */
- init_alloc_root(&result->alloc, 8192, 0,
+ init_alloc_root(&result->alloc, "result", 8192, 0,
MYF(mysql->options.use_thread_specific_memory ?
MY_THREAD_SPECIFIC : 0));
result->alloc.min_malloc=sizeof(MYSQL_ROWS);
@@ -2775,7 +2768,7 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
/* new "use different plugin" packet */
uint len;
auth_plugin_name= (char*)mysql->net.read_pos + 1;
- len= strlen(auth_plugin_name); /* safe as my_net_read always appends \0 */
+ len= (uint)strlen(auth_plugin_name); /* safe as my_net_read always appends \0 */
mpvio.cached_server_reply.pkt_len= pkt_length - len - 2;
mpvio.cached_server_reply.pkt= mysql->net.read_pos + len + 2;
DBUG_PRINT ("info", ("change plugin packet from server for plugin %s",
@@ -2858,6 +2851,7 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len)
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_name");
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_os");
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_platform");
+ rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_server_host");
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_pid");
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_thread");
rc+= mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "_client_version");
@@ -2873,6 +2867,8 @@ set_connect_attributes(MYSQL *mysql, char *buff, size_t buf_len)
"_os", SYSTEM_TYPE);
rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
"_platform", MACHINE_TYPE);
+ rc+= mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
+ "_server_host", mysql->host);
#ifdef __WIN__
snprintf(buff, buf_len, "%lu", (ulong) GetCurrentProcessId());
#else
@@ -2921,9 +2917,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
DBUG_RETURN(0);
}
- if (set_connect_attributes(mysql, buff, sizeof(buff)))
- DBUG_RETURN(0);
-
mysql->methods= &client_methods;
mysql->client_flag=0; /* For handshake */
@@ -3018,7 +3011,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
{
my_socket sock= socket(AF_UNIX, SOCK_STREAM, 0);
DBUG_PRINT("info", ("Using socket"));
- if (sock == SOCKET_ERROR)
+ if (sock == INVALID_SOCKET)
{
set_mysql_extended_error(mysql, CR_SOCKET_CREATE_ERROR,
unknown_sqlstate,
@@ -3065,7 +3058,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
if (!net->vio &&
(mysql->options.protocol == MYSQL_PROTOCOL_PIPE ||
(host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
- (! have_tcpip && (unix_socket || !host && is_NT()))))
+ (! have_tcpip && (unix_socket || !host ))))
{
if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout,
(char**) &host, (char**) &unix_socket)) ==
@@ -3099,7 +3092,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
struct addrinfo *res_lst, hints, *t_res;
int gai_errno;
char port_buf[NI_MAXSERV];
- my_socket sock= SOCKET_ERROR;
+ my_socket sock= INVALID_SOCKET;
int saved_error= 0, status= -1;
unix_socket=0; /* This is not used */
@@ -3147,7 +3140,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
t_res->ai_family, t_res->ai_socktype,
t_res->ai_protocol));
sock= socket(t_res->ai_family, t_res->ai_socktype, t_res->ai_protocol);
- if (sock == SOCKET_ERROR)
+ if (sock == INVALID_SOCKET)
{
saved_error= socket_errno;
continue;
@@ -3164,7 +3157,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
DBUG_PRINT("info", ("Connect socket"));
status= connect_sync_or_async(mysql, net, sock,
- t_res->ai_addr, t_res->ai_addrlen);
+ t_res->ai_addr, (uint)t_res->ai_addrlen);
/*
Here we rely on my_connect() to return success only if the
connect attempt was really successful. Otherwise we would stop
@@ -3189,7 +3182,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
freeaddrinfo(res_lst);
- if (sock == SOCKET_ERROR)
+ if (sock == INVALID_SOCKET)
{
set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
ER(CR_IPSOCK_ERROR), saved_error);
@@ -3380,6 +3373,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
mysql->client_flag= client_flag;
+ set_connect_attributes(mysql, buff, sizeof(buff));
+
/*
Part 2: invoke the plugin to send the authentication data to the server
*/
@@ -3455,7 +3450,7 @@ error:
end_server(mysql);
mysql_close_free(mysql);
if (!(client_flag & CLIENT_REMEMBER_OPTIONS) &&
- !mysql->options.extension->async_context)
+ !(mysql->options.extension && mysql->options.extension->async_context))
mysql_close_free_options(mysql);
}
DBUG_RETURN(0);
@@ -3551,7 +3546,7 @@ my_bool mysql_reconnect(MYSQL *mysql)
if (ctxt)
my_context_install_suspend_resume_hook(ctxt, NULL, NULL);
- DBUG_PRINT("info", ("reconnect succeded"));
+ DBUG_PRINT("info", ("reconnect succeeded"));
tmp_mysql.reconnect= 1;
tmp_mysql.free_me= mysql->free_me;