From 8192608b2a79a682804cc082bf7d3e37832c5a0c Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Wed, 15 Apr 2020 18:03:24 +0200 Subject: [PATCH] Transmit the continuation information to the command_find --- inc/lektor/commands.h | 6 ++---- inc/lektor/database.h | 2 ++ src/commands.c | 9 +++++++-- src/main/lkt.c | 8 +------- src/net/listen.c | 4 ++-- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/inc/lektor/commands.h b/inc/lektor/commands.h index 3329c8a4..1cc95b66 100644 --- a/inc/lektor/commands.h +++ b/inc/lektor/commands.h @@ -70,10 +70,8 @@ enum lkt_find_action { }; /* Find and send karas in the db that match the search expression */ -bool command_find(struct lkt_state *srv, - size_t c, - char *cmd_args[LKT_MESSAGE_ARGS_MAX], - enum lkt_find_action action); +bool command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], + long continuation, enum lkt_find_action action); /* Set options for the lektor such as `random`, `single`, `repeat`, etc */ enum lkt_playback_option { diff --git a/inc/lektor/database.h b/inc/lektor/database.h index 34ddd8c2..a1405c47 100644 --- a/inc/lektor/database.h +++ b/inc/lektor/database.h @@ -96,6 +96,8 @@ struct lkt_search { void (*call)(void); /* Will be casted. */ struct lkt_state *srv; size_t c; + long continuation; /* Is this a continuation from a previous command? */ + int msg_count; /* How much messages we can send. */ }; typedef bool (*lkt_search_database_func)(struct lkt_state *srv, size_t c, int id, int id_len, const char *row); diff --git a/src/commands.c b/src/commands.c index 3ec257a0..7fd47c74 100644 --- a/src/commands.c +++ b/src/commands.c @@ -541,13 +541,18 @@ lkt_callback_insert_v1(struct lkt_state *srv, size_t c, int id, int id_len, cons } bool -command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], +command_find(struct lkt_state *srv, size_t c, char *cmd_args[LKT_MESSAGE_ARGS_MAX], long continuation, enum lkt_find_action action) { char rgx[PATH_MAX], *col_name, *mpd_tag; bool once; struct lkt_message *not_found_msg; - struct lkt_search search = { .srv = srv, .c = c }; + struct lkt_search search = { + .srv = srv, + .c = c, + .continuation = continuation, + .msg_count = lkt_remaining_msg(srv, c), + }; // Check args // if (cmd_args == NULL || cmd_args[0] == NULL) { diff --git a/src/main/lkt.c b/src/main/lkt.c index 834aa483..7d89e64e 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -193,12 +193,6 @@ err: return ret; } -static inline int -write_continue(FILE *sock, const int continuation) -{ - return write_socket_format(sock, "continue %d\n", continuation); -} - static FILE * create_socket(const char *host, const char *port) { @@ -752,7 +746,7 @@ redo: sock = lkt_connect(); if (continuation > 0) - write_continue(sock, continuation); + write_socket_format(sock, "%d ", continuation); write_socket(sock, cmd, strlen(cmd)); diff --git a/src/net/listen.c b/src/net/listen.c index 216e1d75..3ec2fdf1 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -274,10 +274,10 @@ handle_simple_command(struct lkt_state *srv, size_t c, struct lkt_command cmd) goto end_no_send_status; } else if (!strcmp(cmd.name, "searchadd") || !strcmp(cmd.name, "findadd")) - err = !command_find(srv, c, cmd.args, LKT_FND_ACT_RESPOND); + err = !command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_RESPOND); else if (!strcmp(cmd.name, "search") || !strcmp(cmd.name, "find")) - err = !command_find(srv, c, cmd.args, LKT_FND_ACT_RESPOND); + err = !command_find(srv, c, cmd.args, cmd.cont, LKT_FND_ACT_RESPOND); else err = 2; -- GitLab