diff --git a/inc/lektor/commands.h b/inc/lektor/commands.h index 3329c8a48a5e26e2799d045e74eae4251f1797ed..1cc95b662f09d14105422e3284922576e58fdca0 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 34ddd8c2f26767158d287ac1eae07d006fc5d213..a1405c47860fcc7623cf19a2055c2219ee75c300 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 3ec257a0af4c8b3c7f0f36ee7a3fbdb2b58babc5..7fd47c74cfcffe575cb6c4a9800b91f4d601dd9a 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 834aa48311818e785cfbc4133b37aed220fef297..7d89e64e8da00e7b7d9534caa17dbd027013a4c2 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 216e1d75e5fa5168d59d1f0b2aaa49aa9a362ef6..3ec2fdf1e321ecd212cfec5c20a9827065e1be4f 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;