cmd_stats_update(cmd, cmd_stats.commits);
switch (result->ret) {
- case 1:
+ case DICT_COMMIT_RET_OK:
chr = DICT_PROTOCOL_REPLY_OK;
break;
- case 0:
+ case DICT_COMMIT_RET_NOTFOUND:
chr = DICT_PROTOCOL_REPLY_NOTFOUND;
break;
+ case DICT_COMMIT_RET_FAILED:
default:
i_assert(result->error != NULL);
chr = DICT_PROTOCOL_REPLY_FAIL;
{
struct client_dict *dict = cmd->dict;
struct dict_commit_result result = {
- .ret = -1, .error = NULL
+ .ret = DICT_COMMIT_RET_FAILED, .error = NULL
};
if (error != NULL) {
result.error = error;
} else switch (*line) {
case DICT_PROTOCOL_REPLY_OK:
- result.ret = 1;
+ result.ret = DICT_COMMIT_RET_OK;
break;
case DICT_PROTOCOL_REPLY_NOTFOUND:
- result.ret = 0;
+ result.ret = DICT_COMMIT_RET_NOTFOUND;
break;
case DICT_PROTOCOL_REPLY_FAIL: {
const char *error = strchr(line+1, '\t');
break;
}
default:
- result.ret = -1;
+ result.ret = DICT_COMMIT_RET_FAILED;
result.error = t_strdup_printf(
"dict-client: Invalid commit reply: %s", line);
client_dict_disconnect(dict, result.error);
} else if (ctx->error != NULL) {
/* already failed */
struct dict_commit_result result = {
- .ret = -1, .error = ctx->error
+ .ret = DICT_COMMIT_RET_FAILED, .error = ctx->error
};
callback(&result, context);
} else {
/* nothing changed */
struct dict_commit_result result = {
- .ret = 1, .error = NULL
+ .ret = DICT_COMMIT_RET_OK, .error = NULL
};
callback(&result, context);
}
memset(&result, 0, sizeof(result));
if (file_dict_write_changes(ctx, &atomic_inc_not_found, &result.error) < 0)
- result.ret = -1;
+ result.ret = DICT_COMMIT_RET_FAILED;
else if (atomic_inc_not_found)
- result.ret = 0;
+ result.ret = DICT_COMMIT_RET_NOTFOUND;
else
- result.ret = 1;
+ result.ret = DICT_COMMIT_RET_OK;
pool_unref(&ctx->pool);
callback(&result, context);
memcached_ascii_disconnected(struct memcached_ascii_connection *conn,
const char *reason)
{
- const struct dict_commit_result result = { -1, reason };
+ const struct dict_commit_result result = {
+ DICT_COMMIT_RET_FAILED, reason
+ };
const struct memcached_ascii_dict_reply *reply;
connection_disconnect(&conn->conn);
static int memcached_ascii_input_reply(struct memcached_ascii_dict *dict,
const char **error_r)
{
- const struct dict_commit_result result = { 1, NULL };
+ const struct dict_commit_result result = {
+ DICT_COMMIT_RET_OK, NULL
+ };
struct memcached_ascii_dict_reply *replies;
unsigned int count;
int ret;
struct memcached_ascii_dict *dict =
(struct memcached_ascii_dict *)_ctx->dict;
struct dict_memcached_ascii_commit_ctx commit_ctx;
- struct dict_commit_result result = { 1, NULL };
+ struct dict_commit_result result = { DICT_COMMIT_RET_OK, NULL };
if (_ctx->changed) {
memset(&commit_ctx, 0, sizeof(commit_ctx));
static void
redis_disconnected(struct redis_connection *conn, const char *reason)
{
- const struct dict_commit_result result = { -1, reason };
+ const struct dict_commit_result result = {
+ DICT_COMMIT_RET_FAILED, reason
+ };
const struct redis_dict_reply *reply;
conn->dict->db_id_set = FALSE;
reply = array_idx_modifiable(&dict->replies, 0);
i_assert(reply->reply_count > 0);
if (--reply->reply_count == 0) {
- const struct dict_commit_result result = { 1, NULL };
+ const struct dict_commit_result result = {
+ DICT_COMMIT_RET_OK, NULL
+ };
redis_callback(dict, reply, &result);
array_delete(&dict->replies, 0, 1);
/* if we're running in a dict-ioloop, we're handling a
struct redis_dict *dict = (struct redis_dict *)_ctx->dict;
struct redis_dict_reply *reply;
unsigned int i;
- struct dict_commit_result result = { .ret = 1 };
+ struct dict_commit_result result = { .ret = DICT_COMMIT_RET_OK };
i_assert(dict->transaction_open);
dict->transaction_open = FALSE;
memset(&result, 0, sizeof(result));
if (sql_result->error == NULL)
- result.ret = sql_dict_transaction_has_nonexistent(ctx) ? 0 : 1;
+ result.ret = sql_dict_transaction_has_nonexistent(ctx) ?
+ DICT_COMMIT_RET_NOTFOUND : DICT_COMMIT_RET_OK;
else {
result.error = t_strdup_printf("sql dict: commit failed: %s",
sql_result->error);
- result.ret = -1;
+ result.ret = DICT_COMMIT_RET_FAILED;
}
if (ctx->async_callback != NULL)
struct dict_commit_result result;
memset(&result, 0, sizeof(result));
- result.ret = -1;
+ result.ret = DICT_COMMIT_RET_FAILED;
result.error = t_strdup(ctx->error);
if (ctx->prev_inc_map != NULL)
} else if (!_ctx->changed) {
/* nothing changed, no need to commit */
sql_transaction_rollback(&ctx->sql_ctx);
- result.ret = 1;
+ result.ret = DICT_COMMIT_RET_OK;
} else if (async) {
ctx->async_callback = callback;
ctx->async_context = context;
"sql dict: commit failed: %s", error);
} else {
if (sql_dict_transaction_has_nonexistent(ctx))
- result.ret = 0;
+ result.ret = DICT_COMMIT_RET_NOTFOUND;
else
- result.ret = 1;
+ result.ret = DICT_COMMIT_RET_OK;
}
sql_dict_transaction_free(ctx);
const char *error;
};
+enum dict_commit_ret {
+ DICT_COMMIT_RET_OK = 1,
+ DICT_COMMIT_RET_NOTFOUND = 0,
+ DICT_COMMIT_RET_FAILED = -1,
+};
+
struct dict_commit_result {
- int ret;
+ enum dict_commit_ret ret;
const char *error;
};