Commit 9f4b3b9d authored by Daniel Salzman's avatar Daniel Salzman

ctl: add memory pool

parent a4b9314f
......@@ -617,13 +617,13 @@ static const desc_t cmd_table[] = {
[CTL_CONF_GET] = { "conf-get", ctl_conf_read },
[CTL_CONF_SET] = { "conf-set", ctl_conf_modify },
[CTL_CONF_UNSET] = { "conf-unset", ctl_conf_modify },
{ NULL }
};
const char* ctl_cmd_to_str(ctl_cmd_t cmd)
#define MAX_CTL_CODE (sizeof(cmd_table) / sizeof(desc_t) - 1)
const char *ctl_cmd_to_str(ctl_cmd_t cmd)
{
if (cmd < CTL_STATUS || cmd > CTL_CONF_UNSET) {
if (cmd <= CTL_NONE || cmd > MAX_CTL_CODE) {
return NULL;
}
......@@ -636,7 +636,7 @@ ctl_cmd_t ctl_str_to_cmd(const char *cmd_str)
return CTL_NONE;
}
for (ctl_cmd_t cmd = CTL_NONE; cmd_table[cmd].name != NULL; cmd++) {
for (ctl_cmd_t cmd = CTL_NONE + 1; cmd <= MAX_CTL_CODE; cmd++) {
if (strcmp(cmd_str, cmd_table[cmd].name) == 0) {
return cmd;
}
......
......@@ -55,6 +55,7 @@ typedef enum {
/*! Control command parameters. */
typedef struct {
knot_mm_t mm;
knot_ctl_t *ctl;
knot_ctl_type_t type;
knot_ctl_data_t data;
......@@ -68,7 +69,7 @@ typedef struct {
*
* \return Command string or NULL.
*/
const char* ctl_cmd_to_str(ctl_cmd_t cmd);
const char *ctl_cmd_to_str(ctl_cmd_t cmd);
/*!
* Returns a command corresponding to the string.
......
......@@ -14,6 +14,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "contrib/mempattern.h"
#include "contrib/ucw/mempool.h"
#include "knot/common/log.h"
#include "knot/ctl/commands.h"
#include "knot/ctl/process.h"
......@@ -31,6 +33,8 @@ int ctl_process(knot_ctl_t *ctl, server_t *server)
.server = server
};
mm_ctx_mempool(&args.mm, MM_DEFAULT_BLKSIZE);
// Strip redundant/unprocessed data units in the current block.
bool strip = false;
......@@ -40,6 +44,7 @@ int ctl_process(knot_ctl_t *ctl, server_t *server)
if (ret != KNOT_EOK) {
log_debug("control, failed to receive (%s)",
knot_strerror(ret));
mp_delete(args.mm.ctx);
return ret;
}
......@@ -61,6 +66,7 @@ int ctl_process(knot_ctl_t *ctl, server_t *server)
strip = false;
continue;
case KNOT_CTL_TYPE_END:
mp_delete(args.mm.ctx);
return KNOT_EOF;
default:
assert(0);
......@@ -109,6 +115,7 @@ int ctl_process(knot_ctl_t *ctl, server_t *server)
knot_strerror(ret));
}
mp_delete(args.mm.ctx);
return cmd_ret;
}
}
......
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