diff --git a/src/main/lkt.c b/src/main/lkt.c index a17f619fbb0ecfd2abba1b0309197327ffb84f75..2356f74461fc5b99fb0b1f1d3cb8ebcd8605b943 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -157,7 +157,7 @@ end: return i; } -static int +static inline int write_socket(FILE *sock, const char *buff, size_t len) { int ret = 1; @@ -193,6 +193,12 @@ err: return ret; } +static inline int +write_continue(FILE *sock, const int continuation) +{ + return write_socket(sock, "continue %d\n", continuation); +} + static FILE * create_socket(const char *host, const char *port) { @@ -575,7 +581,13 @@ list__(struct lkt_cmd_args *args) else if (args->argc > 1) fail("Invalid argument for the queue command"); - FILE *sock = lkt_connect(); + int continuation = 0; + FILE *sock = NULL; +redo: + sock = lkt_connect(); + + if (continuation > 0) + write_continue(sock, continuation); write_socket(sock, "playlist ", strlen("playlist ")); write_socket(sock, args->argv[0], strlen(args->argv[0])); @@ -585,6 +597,12 @@ list__(struct lkt_cmd_args *args) memset(buff, 0, LKT_MESSAGE_MAX * sizeof(char)); assert(read_socket(sock, buff, LKT_MESSAGE_MAX - 1) > 0); + if (! strncmp(buff, "continue:", strlen("continue:"))) { + continuation = atoi(lkt_skip_key(buff)); + fclose(sock); + goto redo; + } + if (! strncmp(buff, "OK", 2)) exit(EXIT_SUCCESS); else if (! strncmp(buff, "ACK", 3)) @@ -714,9 +732,14 @@ search_with_cmd__(struct lkt_cmd_args *args, const char *cmd) if (!lkt_valid_type(args->argv[0])) fail("Invalid type for the query"); - FILE *sock = lkt_connect(); char buff[LKT_MESSAGE_MAX]; - int i; + int continuation = 0, i; + FILE *sock = NULL; +redo: + sock = lkt_connect(); + + if (continuation > 0) + write_continue(sock, continuation); write_socket(sock, cmd, strlen(cmd)); @@ -728,6 +751,12 @@ search_with_cmd__(struct lkt_cmd_args *args, const char *cmd) memset(buff, 0, LKT_MESSAGE_MAX * sizeof(char)); assert(read_socket(sock, buff, LKT_MESSAGE_MAX - 1) > 0); + if (! strncmp(buff, "continue:", strlen("continue:"))) { + continuation = atoi(lkt_skip_key(buff)); + fclose(sock); + goto redo; + } + if (! strncmp(buff, "OK", 2)) exit(EXIT_SUCCESS); else if (! strncmp(buff, "ACK", 3))