diff --git a/include/maxscale/utils.h b/include/maxscale/utils.h index 6f34e47aa..8f4a6da69 100644 --- a/include/maxscale/utils.h +++ b/include/maxscale/utils.h @@ -87,6 +87,7 @@ int open_unix_socket(enum mxs_socket_type type, struct sockaddr_un *addr, const char *path); int setnonblocking(int fd); +int setblocking(int fd); char *gw_strend(register const char *s); static char gw_randomchar(); int gw_generate_random_str(char *output, int len); diff --git a/server/core/admin.cc b/server/core/admin.cc index 314287e0c..b7f87b422 100644 --- a/server/core/admin.cc +++ b/server/core/admin.cc @@ -61,6 +61,8 @@ bool mxs_admin_init() if (sock > -1) { + setblocking(sock); + if (listen(sock, INT_MAX) == 0) { admin = new (std::nothrow) AdminListener(sock); @@ -121,9 +123,9 @@ AdminListener::~AdminListener() void AdminListener::handle_clients() { - AdminClient* client = accept_client(); + AdminClient* client; - if (client) + while ((client = accept_client())) { SAdminClient sclient(client); ClientList::iterator it = m_clients.insert(m_clients.begin(), sclient); @@ -156,11 +158,6 @@ AdminClient* AdminListener::accept_client() { rval = new AdminClient(fd, addr, m_timeout); } - else if (errno == EAGAIN || errno == EWOULDBLOCK) - { - // TODO: Use epoll for this - thread_millisleep(1); - } else { MXS_ERROR("Failed to accept client: %d, %s\n", errno, mxs_strerror(errno)); diff --git a/server/core/httprequest.cc b/server/core/httprequest.cc index 30c495bf4..b34da086f 100644 --- a/server/core/httprequest.cc +++ b/server/core/httprequest.cc @@ -103,9 +103,13 @@ static bool process_options(string& uri, map& options) if (pos != string::npos) { - string key = opt.substr(0, pos - 1); + string key = opt.substr(0, pos); string value = opt.substr(pos + 1); - options[key] = value; + + if (key.length() && value.length()) + { + options[key] = value; + } } else { diff --git a/server/core/maxscale/httprequest.hh b/server/core/maxscale/httprequest.hh index 69c086bd2..8fc414bb3 100644 --- a/server/core/maxscale/httprequest.hh +++ b/server/core/maxscale/httprequest.hh @@ -104,7 +104,7 @@ public: string rval; map::const_iterator it = m_options.find(option); - if (it != m_headers.end()) + if (it != m_options.end()) { rval = it->second; } diff --git a/server/core/utils.cc b/server/core/utils.cc index 6d7fe1e08..4da40ccc6 100644 --- a/server/core/utils.cc +++ b/server/core/utils.cc @@ -122,6 +122,29 @@ int setnonblocking(int fd) return 0; } +int setblocking(int fd) +{ + int fl; + + if ((fl = fcntl(fd, F_GETFL, 0)) == -1) + { + MXS_ERROR("Can't GET fcntl for %i, errno = %d, %s.", + fd, + errno, + mxs_strerror(errno)); + return 1; + } + + if (fcntl(fd, F_SETFL, fl & ~O_NONBLOCK) == -1) + { + MXS_ERROR("Can't SET fcntl for %i, errno = %d, %s", + fd, + errno, + mxs_strerror(errno)); + return 1; + } + return 0; +} char *gw_strend(register const char *s) {