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:
parent
c4a8f8c8a6
commit
caf2172677
@ -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);
|
||||
|
@ -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));
|
||||
|
@ -103,9 +103,13 @@ static bool process_options(string& uri, map<string, string>& 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
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
string rval;
|
||||
map<string, string>::const_iterator it = m_options.find(option);
|
||||
|
||||
if (it != m_headers.end())
|
||||
if (it != m_options.end())
|
||||
{
|
||||
rval = it->second;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user