Commit d7d10232 authored by Monty's avatar Monty

Changed std::vector<MYSQL_SOCKET> listen_sockets to Dynamic_array

Main reason for this was there was a crash in shutdown of the server
in binlog_encryption.encryption_combo-mix and some other tests because
something in listen_sockets where not initialized. Changing to
Dynamic_array caused things to work.
Other reason for removing std::vector was that it is harder to debug,
and not integrated with DBUG, safemalloc, valgrind or memory
calculation and cause code explosions (extra code generated for each
std::vector type used).
parent cccc96d6
......@@ -125,6 +125,8 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void * element)
void *alloc_dynamic(DYNAMIC_ARRAY *array)
{
DBUG_ENTER("alloc_dynamic");
DBUG_ASSERT(array->size_of_element); /* Ensure init() is called */
if (array->elements == array->max_element)
{
char *new_ptr;
......
......@@ -23,12 +23,11 @@
#include <mysql/psi/mysql_socket.h>
#include <sddl.h>
#include <vector>
#include <handle_connections_win.h>
/* From mysqld.cc */
extern HANDLE hEventShutdown;
extern std::vector<MYSQL_SOCKET> listen_sockets;
extern Dynamic_array<MYSQL_SOCKET> listen_sockets;
#ifdef HAVE_POOL_OF_THREADS
extern PTP_CALLBACK_ENVIRON get_threadpool_win_callback_environ();
extern void tp_win_callback_prolog();
......@@ -292,7 +291,7 @@ retry :
return;
}
SOCKET s= mysql_socket_getfd(listen_sockets[0]);
SOCKET s= mysql_socket_getfd(listen_sockets.at(0));
GUID guid_AcceptEx= WSAID_ACCEPTEX;
GUID guid_GetAcceptExSockaddrs= WSAID_GETACCEPTEXSOCKADDRS;
......@@ -557,11 +556,11 @@ void network_init_win()
Socket_Listener::init_winsock_extensions();
/* Listen for TCP connections on "extra-port" (no threadpool).*/
for (std::vector<MYSQL_SOCKET>::iterator it= listen_sockets.begin();
it != listen_sockets.end(); ++it)
for (uint i= 0 ; i < listen_sockets.elements() ; i++)
{
if (it->is_extra_port)
all_listeners.push_back(new Socket_Listener(*it, 0));
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
if (sock->is_extra_port)
all_listeners.push_back(new Socket_Listener(*sock, 0));
}
/* Listen for named pipe connections */
......@@ -574,16 +573,16 @@ void network_init_win()
all_listeners.push_back(new Pipe_Listener());
}
for (std::vector<MYSQL_SOCKET>::iterator it= listen_sockets.begin();
it != listen_sockets.end(); ++it)
for (uint i= 0 ; i < listen_sockets.elements() ; i++)
{
if (it->is_extra_port)
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
if (sock->is_extra_port)
continue;
/* Wait for TCP connections.*/
SetFileCompletionNotificationModes((HANDLE)it->fd,
SetFileCompletionNotificationModes((HANDLE) sock->fd,
FILE_SKIP_SET_EVENT_ON_HANDLE);
all_listeners.push_back(
new Socket_Listener(*it, get_threadpool_win_callback_environ()));
new Socket_Listener(*sock, get_threadpool_win_callback_environ()));
}
if (all_listeners.size() == 0 && !opt_bootstrap)
......
......@@ -1348,7 +1348,8 @@ static Buffered_logs buffered_logs;
struct my_rnd_struct sql_rand; ///< used by sql_class.cc:THD::THD()
#ifndef EMBEDDED_LIBRARY
std::vector<MYSQL_SOCKET> listen_sockets;
Dynamic_array<MYSQL_SOCKET> listen_sockets(PSI_INSTRUMENT_MEM, 0);
bool unix_sock_is_online= false;
/**
Error reporter that buffer log messages.
......@@ -1690,14 +1691,14 @@ static void close_connections(void)
/* Abort listening to new connections */
DBUG_PRINT("quit",("Closing sockets"));
for (std::vector<MYSQL_SOCKET>::iterator sock = listen_sockets.begin();
sock != listen_sockets.end(); ++sock)
for (uint i= 0 ; i < listen_sockets.elements() ; i++)
{
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
(void) mysql_socket_close(*sock);
if (sock->is_unix_domain_socket)
(void) unlink(mysqld_unix_port);
}
listen_sockets.clear();
listen_sockets.free_memory();
end_thr_alarm(0); // Abort old alarms.
......@@ -1787,9 +1788,9 @@ static void close_server_sock()
#ifdef HAVE_CLOSE_SERVER_SOCK
DBUG_ENTER("close_server_sock");
for (std::vector<MYSQL_SOCKET>::iterator sock= listen_sockets.begin();
sock != listen_sockets.end(); ++sock)
for (uint i= 0 ; i < listen_sockets.elements() ; i++)
{
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
if (sock->is_unix_domain_socket)
{
close_socket(*sock, "unix/IP");
......@@ -1800,7 +1801,7 @@ static void close_server_sock()
close_socket(*sock, "TCP/IP");
}
}
listen_sockets.clear();
listen_sockets.free_memory();
DBUG_VOID_RETURN;
#endif
......@@ -2236,7 +2237,7 @@ static void set_root(const char *path)
*/
static void activate_tcp_port(uint port,
std::vector<MYSQL_SOCKET> *listen_sockets,
Dynamic_array<MYSQL_SOCKET> *sockets,
bool is_extra_port= false)
{
struct addrinfo *ai, *a;
......@@ -2377,7 +2378,7 @@ static void activate_tcp_port(uint port,
(void) fcntl(mysql_socket_getfd(ip_sock), F_SETFD, FD_CLOEXEC);
#endif
ip_sock.is_extra_port= is_extra_port;
listen_sockets->push_back(ip_sock);
sockets->push(ip_sock);
}
}
......@@ -2443,7 +2444,7 @@ static void network_init(void)
}
unix_sock.is_unix_domain_socket= true;
listen_sockets.push_back(unix_sock);
listen_sockets.push(unix_sock);
unix_sock_is_online= true;
mysql_socket_set_thread_owner(unix_sock);
......@@ -5932,7 +5933,8 @@ void handle_connections_sockets()
struct sockaddr_storage cAddr;
int retval;
#ifdef HAVE_POLL
std::vector<struct pollfd> fds; // for ip_sock, unix_sock and extra_ip_sock
// for ip_sock, unix_sock and extra_ip_sock
Dynamic_array<struct pollfd> fds(PSI_INSTRUMENT_MEM);
#else
fd_set readFDs,clientFDs;
#endif
......@@ -5940,21 +5942,22 @@ void handle_connections_sockets()
DBUG_ENTER("handle_connections_sockets");
#ifdef HAVE_POLL
fds.resize(listen_sockets.size());
for (size_t i= 0; i < listen_sockets.size(); i++)
{
mysql_socket_set_thread_owner(listen_sockets[i]);
fds[i].fd= mysql_socket_getfd(listen_sockets[i]);
fds[i].events= POLLIN;
set_non_blocking_if_supported(listen_sockets[i]);
struct pollfd local_fds;
mysql_socket_set_thread_owner(listen_sockets.at(i));
local_fds.fd= mysql_socket_getfd(listen_sockets.at(i));
local_fds.events= POLLIN;
fds.push(local_fds);
set_non_blocking_if_supported(listen_sockets.at(i));
}
#else
FD_ZERO(&clientFDs);
for (size_t i= 0; i < listen_sockets.size(); i++)
{
int fd= mysql_socket_getfd(listen_sockets[i]);
int fd= mysql_socket_getfd(listen_sockets.at(i));
FD_SET(fd, &clientFDs);
set_non_blocking_if_supported(listen_sockets[i]);
set_non_blocking_if_supported(listen_sockets.at(i));
}
#endif
......@@ -5965,7 +5968,7 @@ void handle_connections_sockets()
while (!abort_loop)
{
#ifdef HAVE_POLL
retval= poll(fds.data(), fds.size(), -1);
retval= poll(fds.get_pos(0), fds.size(), -1);
#else
readFDs=clientFDs;
retval= select(FD_SETSIZE, &readFDs, NULL, NULL, NULL);
......@@ -5994,18 +5997,18 @@ void handle_connections_sockets()
#ifdef HAVE_POLL
for (size_t i= 0; i < fds.size(); ++i)
{
if (fds[i].revents & POLLIN)
if (fds.at(i).revents & POLLIN)
{
sock= listen_sockets[i];
sock= listen_sockets.at(i);
break;
}
}
#else // HAVE_POLL
for (size_t i=0; i < listen_sockets.size(); i++)
{
if (FD_ISSET(mysql_socket_getfd(listen_sockets[i]), &readFDs))
if (FD_ISSET(mysql_socket_getfd(listen_sockets.at(i)), &readFDs))
{
sock= listen_sockets[i];
sock= listen_sockets.at(i);
break;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment