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) ...@@ -125,6 +125,8 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, const void * element)
void *alloc_dynamic(DYNAMIC_ARRAY *array) void *alloc_dynamic(DYNAMIC_ARRAY *array)
{ {
DBUG_ENTER("alloc_dynamic"); DBUG_ENTER("alloc_dynamic");
DBUG_ASSERT(array->size_of_element); /* Ensure init() is called */
if (array->elements == array->max_element) if (array->elements == array->max_element)
{ {
char *new_ptr; char *new_ptr;
......
...@@ -23,12 +23,11 @@ ...@@ -23,12 +23,11 @@
#include <mysql/psi/mysql_socket.h> #include <mysql/psi/mysql_socket.h>
#include <sddl.h> #include <sddl.h>
#include <vector> #include <vector>
#include <handle_connections_win.h> #include <handle_connections_win.h>
/* From mysqld.cc */ /* From mysqld.cc */
extern HANDLE hEventShutdown; extern HANDLE hEventShutdown;
extern std::vector<MYSQL_SOCKET> listen_sockets; extern Dynamic_array<MYSQL_SOCKET> listen_sockets;
#ifdef HAVE_POOL_OF_THREADS #ifdef HAVE_POOL_OF_THREADS
extern PTP_CALLBACK_ENVIRON get_threadpool_win_callback_environ(); extern PTP_CALLBACK_ENVIRON get_threadpool_win_callback_environ();
extern void tp_win_callback_prolog(); extern void tp_win_callback_prolog();
...@@ -292,7 +291,7 @@ retry : ...@@ -292,7 +291,7 @@ retry :
return; 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_AcceptEx= WSAID_ACCEPTEX;
GUID guid_GetAcceptExSockaddrs= WSAID_GETACCEPTEXSOCKADDRS; GUID guid_GetAcceptExSockaddrs= WSAID_GETACCEPTEXSOCKADDRS;
...@@ -557,11 +556,11 @@ void network_init_win() ...@@ -557,11 +556,11 @@ void network_init_win()
Socket_Listener::init_winsock_extensions(); Socket_Listener::init_winsock_extensions();
/* Listen for TCP connections on "extra-port" (no threadpool).*/ /* Listen for TCP connections on "extra-port" (no threadpool).*/
for (std::vector<MYSQL_SOCKET>::iterator it= listen_sockets.begin(); for (uint i= 0 ; i < listen_sockets.elements() ; i++)
it != listen_sockets.end(); ++it)
{ {
if (it->is_extra_port) MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
all_listeners.push_back(new Socket_Listener(*it, 0)); if (sock->is_extra_port)
all_listeners.push_back(new Socket_Listener(*sock, 0));
} }
/* Listen for named pipe connections */ /* Listen for named pipe connections */
...@@ -574,16 +573,16 @@ void network_init_win() ...@@ -574,16 +573,16 @@ void network_init_win()
all_listeners.push_back(new Pipe_Listener()); all_listeners.push_back(new Pipe_Listener());
} }
for (std::vector<MYSQL_SOCKET>::iterator it= listen_sockets.begin(); for (uint i= 0 ; i < listen_sockets.elements() ; i++)
it != listen_sockets.end(); ++it)
{ {
if (it->is_extra_port) MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
if (sock->is_extra_port)
continue; continue;
/* Wait for TCP connections.*/ /* Wait for TCP connections.*/
SetFileCompletionNotificationModes((HANDLE)it->fd, SetFileCompletionNotificationModes((HANDLE) sock->fd,
FILE_SKIP_SET_EVENT_ON_HANDLE); FILE_SKIP_SET_EVENT_ON_HANDLE);
all_listeners.push_back( 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) if (all_listeners.size() == 0 && !opt_bootstrap)
......
...@@ -1348,7 +1348,8 @@ static Buffered_logs buffered_logs; ...@@ -1348,7 +1348,8 @@ static Buffered_logs buffered_logs;
struct my_rnd_struct sql_rand; ///< used by sql_class.cc:THD::THD() struct my_rnd_struct sql_rand; ///< used by sql_class.cc:THD::THD()
#ifndef EMBEDDED_LIBRARY #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; bool unix_sock_is_online= false;
/** /**
Error reporter that buffer log messages. Error reporter that buffer log messages.
...@@ -1690,14 +1691,14 @@ static void close_connections(void) ...@@ -1690,14 +1691,14 @@ static void close_connections(void)
/* Abort listening to new connections */ /* Abort listening to new connections */
DBUG_PRINT("quit",("Closing sockets")); DBUG_PRINT("quit",("Closing sockets"));
for (std::vector<MYSQL_SOCKET>::iterator sock = listen_sockets.begin(); for (uint i= 0 ; i < listen_sockets.elements() ; i++)
sock != listen_sockets.end(); ++sock)
{ {
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
(void) mysql_socket_close(*sock); (void) mysql_socket_close(*sock);
if (sock->is_unix_domain_socket) if (sock->is_unix_domain_socket)
(void) unlink(mysqld_unix_port); (void) unlink(mysqld_unix_port);
} }
listen_sockets.clear(); listen_sockets.free_memory();
end_thr_alarm(0); // Abort old alarms. end_thr_alarm(0); // Abort old alarms.
...@@ -1787,9 +1788,9 @@ static void close_server_sock() ...@@ -1787,9 +1788,9 @@ static void close_server_sock()
#ifdef HAVE_CLOSE_SERVER_SOCK #ifdef HAVE_CLOSE_SERVER_SOCK
DBUG_ENTER("close_server_sock"); DBUG_ENTER("close_server_sock");
for (std::vector<MYSQL_SOCKET>::iterator sock= listen_sockets.begin(); for (uint i= 0 ; i < listen_sockets.elements() ; i++)
sock != listen_sockets.end(); ++sock)
{ {
MYSQL_SOCKET *sock= listen_sockets.get_pos(i);
if (sock->is_unix_domain_socket) if (sock->is_unix_domain_socket)
{ {
close_socket(*sock, "unix/IP"); close_socket(*sock, "unix/IP");
...@@ -1800,7 +1801,7 @@ static void close_server_sock() ...@@ -1800,7 +1801,7 @@ static void close_server_sock()
close_socket(*sock, "TCP/IP"); close_socket(*sock, "TCP/IP");
} }
} }
listen_sockets.clear(); listen_sockets.free_memory();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
#endif #endif
...@@ -2236,7 +2237,7 @@ static void set_root(const char *path) ...@@ -2236,7 +2237,7 @@ static void set_root(const char *path)
*/ */
static void activate_tcp_port(uint port, static void activate_tcp_port(uint port,
std::vector<MYSQL_SOCKET> *listen_sockets, Dynamic_array<MYSQL_SOCKET> *sockets,
bool is_extra_port= false) bool is_extra_port= false)
{ {
struct addrinfo *ai, *a; struct addrinfo *ai, *a;
...@@ -2377,7 +2378,7 @@ static void activate_tcp_port(uint port, ...@@ -2377,7 +2378,7 @@ static void activate_tcp_port(uint port,
(void) fcntl(mysql_socket_getfd(ip_sock), F_SETFD, FD_CLOEXEC); (void) fcntl(mysql_socket_getfd(ip_sock), F_SETFD, FD_CLOEXEC);
#endif #endif
ip_sock.is_extra_port= is_extra_port; 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) ...@@ -2443,7 +2444,7 @@ static void network_init(void)
} }
unix_sock.is_unix_domain_socket= true; unix_sock.is_unix_domain_socket= true;
listen_sockets.push_back(unix_sock); listen_sockets.push(unix_sock);
unix_sock_is_online= true; unix_sock_is_online= true;
mysql_socket_set_thread_owner(unix_sock); mysql_socket_set_thread_owner(unix_sock);
...@@ -5932,7 +5933,8 @@ void handle_connections_sockets() ...@@ -5932,7 +5933,8 @@ void handle_connections_sockets()
struct sockaddr_storage cAddr; struct sockaddr_storage cAddr;
int retval; int retval;
#ifdef HAVE_POLL #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 #else
fd_set readFDs,clientFDs; fd_set readFDs,clientFDs;
#endif #endif
...@@ -5940,21 +5942,22 @@ void handle_connections_sockets() ...@@ -5940,21 +5942,22 @@ void handle_connections_sockets()
DBUG_ENTER("handle_connections_sockets"); DBUG_ENTER("handle_connections_sockets");
#ifdef HAVE_POLL #ifdef HAVE_POLL
fds.resize(listen_sockets.size());
for (size_t i= 0; i < listen_sockets.size(); i++) for (size_t i= 0; i < listen_sockets.size(); i++)
{ {
mysql_socket_set_thread_owner(listen_sockets[i]); struct pollfd local_fds;
fds[i].fd= mysql_socket_getfd(listen_sockets[i]); mysql_socket_set_thread_owner(listen_sockets.at(i));
fds[i].events= POLLIN; local_fds.fd= mysql_socket_getfd(listen_sockets.at(i));
set_non_blocking_if_supported(listen_sockets[i]); local_fds.events= POLLIN;
fds.push(local_fds);
set_non_blocking_if_supported(listen_sockets.at(i));
} }
#else #else
FD_ZERO(&clientFDs); FD_ZERO(&clientFDs);
for (size_t i= 0; i < listen_sockets.size(); i++) 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); FD_SET(fd, &clientFDs);
set_non_blocking_if_supported(listen_sockets[i]); set_non_blocking_if_supported(listen_sockets.at(i));
} }
#endif #endif
...@@ -5965,7 +5968,7 @@ void handle_connections_sockets() ...@@ -5965,7 +5968,7 @@ void handle_connections_sockets()
while (!abort_loop) while (!abort_loop)
{ {
#ifdef HAVE_POLL #ifdef HAVE_POLL
retval= poll(fds.data(), fds.size(), -1); retval= poll(fds.get_pos(0), fds.size(), -1);
#else #else
readFDs=clientFDs; readFDs=clientFDs;
retval= select(FD_SETSIZE, &readFDs, NULL, NULL, NULL); retval= select(FD_SETSIZE, &readFDs, NULL, NULL, NULL);
...@@ -5994,18 +5997,18 @@ void handle_connections_sockets() ...@@ -5994,18 +5997,18 @@ void handle_connections_sockets()
#ifdef HAVE_POLL #ifdef HAVE_POLL
for (size_t i= 0; i < fds.size(); ++i) 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; break;
} }
} }
#else // HAVE_POLL #else // HAVE_POLL
for (size_t i=0; i < listen_sockets.size(); i++) 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; 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