summaryrefslogtreecommitdiff
path: root/client/mysqltest.c
diff options
context:
space:
mode:
authorunknown <msvensson@pilot.(none)>2007-08-28 16:47:05 +0200
committerunknown <msvensson@pilot.(none)>2007-08-28 16:47:05 +0200
commit2bb6a44af1dd478690eac91ce8ae89d786dd0838 (patch)
tree00c2d5216e8c84a3abe5cbce13e31111e6f4f87d /client/mysqltest.c
parent5f524dadcdad94c9a2b9dcbd4cf8031981c891c6 (diff)
downloadmariadb-git-2bb6a44af1dd478690eac91ce8ae89d786dd0838.tar.gz
Streamline "do_close_connection" and "do_send_quit"
Fix typo, "next_con" -> "con" client/mysqltest.c: Reuse "find_connection_by_name" both from "do_close_connection" and "do_send_quit" Adjust alignment of comment Fix typo in "do_close_connection", it used the global variable "next_con" instead of local variable "con"
Diffstat (limited to 'client/mysqltest.c')
-rw-r--r--client/mysqltest.c122
1 files changed, 57 insertions, 65 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c
index 23a23dc5719..b2b579528ae 100644
--- a/client/mysqltest.c
+++ b/client/mysqltest.c
@@ -2983,15 +2983,30 @@ void do_diff_files(struct st_command *command)
DBUG_VOID_RETURN;
}
- /*
- SYNOPSIS
- do_send_quit
- command called command
- DESCRIPTION
- Sends a simple quit command to the server for the named connection.
+struct st_connection * find_connection_by_name(const char *name)
+{
+ struct st_connection *con;
+ for (con= connections; con < next_con; con++)
+ {
+ if (!strcmp(con->name, name))
+ {
+ return con;
+ }
+ }
+ return 0; /* Connection not found */
+}
+
- */
+/*
+ SYNOPSIS
+ do_send_quit
+ command called command
+
+ DESCRIPTION
+ Sends a simple quit command to the server for the named connection.
+
+*/
void do_send_quit(struct st_command *command)
{
@@ -3002,7 +3017,7 @@ void do_send_quit(struct st_command *command)
DBUG_PRINT("enter",("name: '%s'",p));
if (!*p)
- die("Missing connection name in do_send_quit");
+ die("Missing connection name in send_quit");
name= p;
while (*p && !my_isspace(charset_info,*p))
p++;
@@ -3011,17 +3026,12 @@ void do_send_quit(struct st_command *command)
*p++= 0;
command->last_argument= p;
- /* Loop through connection pool for connection to close */
- for (con= connections; con < next_con; con++)
- {
- DBUG_PRINT("info", ("con->name: %s", con->name));
- if (!strcmp(con->name, name))
- {
- simple_command(&con->mysql,COM_QUIT,NullS,0,1);
- DBUG_VOID_RETURN;
- }
- }
- die("connection '%s' not found in connection pool", name);
+ if (!(con= find_connection_by_name(name)))
+ die("connection '%s' not found in connection pool", name);
+
+ simple_command(&con->mysql,COM_QUIT,NullS,0,1);
+
+ DBUG_VOID_RETURN;
}
@@ -3858,20 +3868,6 @@ void set_reconnect(MYSQL* mysql, int val)
}
-struct st_connection * find_connection_by_name(const char *name)
-{
- struct st_connection *con;
- for (con= connections; con < next_con; con++)
- {
- if (!strcmp(con->name, name))
- {
- return con;
- }
- }
- return 0; /* Connection not found */
-}
-
-
int select_connection_name(const char *name)
{
DBUG_ENTER("select_connection2");
@@ -3919,44 +3915,40 @@ void do_close_connection(struct st_command *command)
*p++= 0;
command->last_argument= p;
- /* Loop through connection pool for connection to close */
- for (con= connections; con < next_con; con++)
+ if (!(con= find_connection_by_name(name)))
+ die("connection '%s' not found in connection pool", name);
+
+ DBUG_PRINT("info", ("Closing connection %s", con->name));
+#ifndef EMBEDDED_LIBRARY
+ if (command->type == Q_DIRTY_CLOSE)
{
- DBUG_PRINT("info", ("con->name: %s", con->name));
- if (!strcmp(con->name, name))
+ if (con->mysql.net.vio)
{
- DBUG_PRINT("info", ("Closing connection %s", con->name));
-#ifndef EMBEDDED_LIBRARY
- if (command->type == Q_DIRTY_CLOSE)
- {
- if (con->mysql.net.vio)
- {
- vio_delete(con->mysql.net.vio);
- con->mysql.net.vio = 0;
- }
- }
+ vio_delete(con->mysql.net.vio);
+ con->mysql.net.vio = 0;
+ }
+ }
#endif
- if (next_con->stmt)
- mysql_stmt_close(next_con->stmt);
- next_con->stmt= 0;
+ if (con->stmt)
+ mysql_stmt_close(con->stmt);
+ con->stmt= 0;
- mysql_close(&con->mysql);
- if (con->util_mysql)
- mysql_close(con->util_mysql);
- con->util_mysql= 0;
- my_free(con->name, MYF(0));
+ mysql_close(&con->mysql);
- /*
- When the connection is closed set name to "-closed_connection-"
- to make it possible to reuse the connection name.
- */
- if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
- die("Out of memory");
+ if (con->util_mysql)
+ mysql_close(con->util_mysql);
+ con->util_mysql= 0;
- DBUG_VOID_RETURN;
- }
- }
- die("connection '%s' not found in connection pool", name);
+ my_free(con->name, MYF(0));
+
+ /*
+ When the connection is closed set name to "-closed_connection-"
+ to make it possible to reuse the connection name.
+ */
+ if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
+ die("Out of memory");
+
+ DBUG_VOID_RETURN;
}