22 #include <drizzled/errmsg_print.h>
23 #include <drizzled/error.h>
24 #include <drizzled/gettext.h>
25 #include <drizzled/plugin/listen.h>
26 #include <drizzled/plugin/listen.h>
27 #include <drizzled/plugin/null_client.h>
29 #ifdef HAVE_SYS_SOCKET_H
30 #include <sys/socket.h>
38 static std::vector<plugin::Listen*> listen_list;
39 std::vector<plugin::Listen*> listen_fd_list;
40 std::vector<pollfd> fd_list;
44 ListenVector& Listen::getListenProtocols()
51 listen_list.push_back(listen_obj);
57 listen_list.erase(std::remove(listen_list.begin(), listen_list.end(), listen_obj), listen_list.end());
67 errmsg_printf(error::ERROR, _(
"Error getting file descriptors"));
71 fd_list.resize(fd_count + fds.size() + 1);
73 BOOST_FOREACH(
int fd, fds)
75 fd_list[fd_count].fd= fd;
76 fd_list[fd_count].events= POLLIN | POLLERR;
77 listen_fd_list.push_back(it);
84 errmsg_printf(error::ERROR, _(
"No sockets could be bound for listening"));
92 if (pipe(wakeup_pipe) == -1)
98 fd_list.resize(fd_count + 1);
100 fd_list[fd_count].fd= wakeup_pipe[0];
101 fd_list[fd_count].events= POLLIN | POLLERR;
111 int ready= poll(&fd_list[0], fd_count, -1);
116 sql_perror(
"poll()");
123 for (uint32_t x= 0; x < fd_count; x++)
125 if (fd_list[x].revents != POLLIN)
129 if (x == fd_count - 1)
132 for (x= 0; x < fd_count; x++)
134 (void) ::shutdown(fd_list[x].fd, SHUT_RDWR);
135 (void) close(fd_list[x].fd);
140 (void) close(wakeup_pipe[1]);
145 if (
plugin::Client* client= listen_fd_list[x]->getClient(fd_list[x].fd))
158 ssize_t ret= write(wakeup_pipe[1],
"\0", 1);