MXS-1220: Fix minor problems with admin thread
The admin thread now uses blocking IO. This is not optimal but it simplifies the code by some amount. Fixed option processing removing one extra character from key name. Use correct member variable when checking for the option map end.
This commit is contained in:

committed by
Markus Mäkelä

parent
c4a8f8c8a6
commit
caf2172677
@ -87,6 +87,7 @@ int open_unix_socket(enum mxs_socket_type type, struct sockaddr_un *addr,
|
|||||||
const char *path);
|
const char *path);
|
||||||
|
|
||||||
int setnonblocking(int fd);
|
int setnonblocking(int fd);
|
||||||
|
int setblocking(int fd);
|
||||||
char *gw_strend(register const char *s);
|
char *gw_strend(register const char *s);
|
||||||
static char gw_randomchar();
|
static char gw_randomchar();
|
||||||
int gw_generate_random_str(char *output, int len);
|
int gw_generate_random_str(char *output, int len);
|
||||||
|
@ -61,6 +61,8 @@ bool mxs_admin_init()
|
|||||||
|
|
||||||
if (sock > -1)
|
if (sock > -1)
|
||||||
{
|
{
|
||||||
|
setblocking(sock);
|
||||||
|
|
||||||
if (listen(sock, INT_MAX) == 0)
|
if (listen(sock, INT_MAX) == 0)
|
||||||
{
|
{
|
||||||
admin = new (std::nothrow) AdminListener(sock);
|
admin = new (std::nothrow) AdminListener(sock);
|
||||||
@ -121,9 +123,9 @@ AdminListener::~AdminListener()
|
|||||||
|
|
||||||
void AdminListener::handle_clients()
|
void AdminListener::handle_clients()
|
||||||
{
|
{
|
||||||
AdminClient* client = accept_client();
|
AdminClient* client;
|
||||||
|
|
||||||
if (client)
|
while ((client = accept_client()))
|
||||||
{
|
{
|
||||||
SAdminClient sclient(client);
|
SAdminClient sclient(client);
|
||||||
ClientList::iterator it = m_clients.insert(m_clients.begin(), sclient);
|
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);
|
rval = new AdminClient(fd, addr, m_timeout);
|
||||||
}
|
}
|
||||||
else if (errno == EAGAIN || errno == EWOULDBLOCK)
|
|
||||||
{
|
|
||||||
// TODO: Use epoll for this
|
|
||||||
thread_millisleep(1);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXS_ERROR("Failed to accept client: %d, %s\n", errno, mxs_strerror(errno));
|
MXS_ERROR("Failed to accept client: %d, %s\n", errno, mxs_strerror(errno));
|
||||||
|
@ -103,9 +103,13 @@ static bool process_options(string& uri, map<string, string>& options)
|
|||||||
|
|
||||||
if (pos != string::npos)
|
if (pos != string::npos)
|
||||||
{
|
{
|
||||||
string key = opt.substr(0, pos - 1);
|
string key = opt.substr(0, pos);
|
||||||
string value = opt.substr(pos + 1);
|
string value = opt.substr(pos + 1);
|
||||||
options[key] = value;
|
|
||||||
|
if (key.length() && value.length())
|
||||||
|
{
|
||||||
|
options[key] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -104,7 +104,7 @@ public:
|
|||||||
string rval;
|
string rval;
|
||||||
map<string, string>::const_iterator it = m_options.find(option);
|
map<string, string>::const_iterator it = m_options.find(option);
|
||||||
|
|
||||||
if (it != m_headers.end())
|
if (it != m_options.end())
|
||||||
{
|
{
|
||||||
rval = it->second;
|
rval = it->second;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,29 @@ int setnonblocking(int fd)
|
|||||||
return 0;
|
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)
|
char *gw_strend(register const char *s)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user