From 52fd6119e9cb60239ea5af127ea208725d5b091b Mon Sep 17 00:00:00 2001 From: Sarthak Aggarwal Date: Mon, 16 Dec 2024 14:39:56 -0800 Subject: [PATCH] addressing comments on modularizing Signed-off-by: Sarthak Aggarwal --- src/networking.c | 378 +++++++++++++++++++++++------------------------ 1 file changed, 188 insertions(+), 190 deletions(-) diff --git a/src/networking.c b/src/networking.c index b93d4962ae..9fd9efe92c 100644 --- a/src/networking.c +++ b/src/networking.c @@ -65,31 +65,31 @@ typedef struct { int skipme; } clientFilter; -void clientCommandHelp(client *c); -void clientCommandID(client *c); -void clientCommandInfo(client *c); -void clientCommandList(client *c); -void clientCommandReply(client *c); -void clientCommandNoEvict(client *c); -void clientCommandKill(client *c); -void clientCommandUnblock(client *c); -void clientCommandSetName(client *c); -void clientCommandGetName(client *c); -void clientCommandUnpause(client *c); -void clientCommandPause(client *c); -void clientCommandTracking(client *c); -void clientCommandCaching(client *c); -void clientCommandGetredir(client *c); -void clientCommandTrackingInfo(client *c); -void clientCommandNoTouch(client *c); -void clientCommandCapa(client *c); -void clientCommandImportSource(client *c); +static void clientCommandHelp(client *c); +static void clientCommandID(client *c); +static void clientCommandInfo(client *c); +static void clientCommandList(client *c); +static void clientCommandReply(client *c); +static void clientCommandNoEvict(client *c); +static void clientCommandKill(client *c); +static void clientCommandUnblock(client *c); +static void clientCommandSetName(client *c); +static void clientCommandGetName(client *c); +static void clientCommandUnpause(client *c); +static void clientCommandPause(client *c); +static void clientCommandTracking(client *c); +static void clientCommandCaching(client *c); +static void clientCommandGetredir(client *c); +static void clientCommandTrackingInfo(client *c); +static void clientCommandNoTouch(client *c); +static void clientCommandCapa(client *c); +static void clientCommandImportSource(client *c); static void setProtocolError(const char *errstr, client *c); static void pauseClientsByClient(mstime_t end, int isPauseClientAll); int postponeClientRead(client *c); char *getClientSockname(client *c); -int parseClientFilters(client *c, int i, clientFilter *filter); -int clientMatchesFilter(client *client, clientFilter client_filter); +static int parseClientFiltersOrReply(client *c, int i, clientFilter *filter); +static int clientMatchesFilter(client *client, clientFilter client_filter); sds getAllFilteredClientsInfoString(clientFilter *client_filter, int hide_user_data); int ProcessingEventsWhileBlocked = 0; /* See processEventsWhileBlocked(). */ @@ -3619,7 +3619,7 @@ void quitCommand(client *c) { c->flag.close_after_reply = 1; } -int parseClientFilters(client *c, int i, clientFilter *filter) { +static int parseClientFiltersOrReply(client *c, int i, clientFilter *filter) { while (i < c->argc) { int moreargs = c->argc > i + 1; @@ -3695,7 +3695,7 @@ int parseClientFilters(client *c, int i, clientFilter *filter) { return C_OK; } -int clientMatchesFilter(client *client, clientFilter client_filter) { +static int clientMatchesFilter(client *client, clientFilter client_filter) { // Check each filter condition and return false if the client does not match. if (client_filter.addr && strcmp(getClientPeerId(client), client_filter.addr) != 0) return 0; if (client_filter.laddr && strcmp(getClientSockname(client), client_filter.laddr) != 0) return 0; @@ -3709,7 +3709,7 @@ int clientMatchesFilter(client *client, clientFilter client_filter) { return 1; } -void clientCommandHelp(client *c) { +static void clientCommandHelp(client *c) { const char *help[] = { "CACHING (YES|NO)", " Enable/disable tracking of the keys for next command in OPTIN/OPTOUT modes.", @@ -3774,23 +3774,22 @@ void clientCommandHelp(client *c) { " Mark this connection as an import source if import-mode is enabled.", " Sync tools can set their connections into 'import-source' state to visit", " expired keys.", - NULL - }; + NULL}; addReplyHelp(c, help); } -void clientCommandID(client *c) { +static void clientCommandID(client *c) { addReplyLongLong(c, c->id); } -void clientCommandInfo(client *c) { +static void clientCommandInfo(client *c) { sds info = catClientInfoString(sdsempty(), c, 0); info = sdscatlen(info, "\n", 1); addReplyVerbatim(c, info, sdslen(info), "txt"); sdsfree(info); } -void clientCommandList(client *c) { +static void clientCommandList(client *c) { int type = -1; sds response = NULL; @@ -3798,7 +3797,7 @@ void clientCommandList(client *c) { clientFilter filter = {.ids = NULL, .max_age = 0, .addr = NULL, .laddr = NULL, .user = NULL, .type = -1, .skipme = 0}; int i = 2; - if (parseClientFilters(c, i, &filter) != C_OK) { + if (parseClientFiltersOrReply(c, i, &filter) != C_OK) { zfree(filter.ids); return; } @@ -3814,7 +3813,7 @@ void clientCommandList(client *c) { sdsfree(response); } -void clientCommandReply(client *c) { +static void clientCommandReply(client *c) { /* CLIENT REPLY ON|OFF|SKIP */ if (!strcasecmp(c->argv[2]->ptr, "on")) { c->flag.reply_skip = 0; @@ -3830,7 +3829,7 @@ void clientCommandReply(client *c) { } } -void clientCommandNoEvict(client *c) { +static void clientCommandNoEvict(client *c) { /* CLIENT NO-EVICT ON|OFF */ if (!strcasecmp(c->argv[2]->ptr, "on")) { c->flag.no_evict = 1; @@ -3846,75 +3845,75 @@ void clientCommandNoEvict(client *c) { } } -void clientCommandKill(client *c) { - /* CLIENT KILL - * CLIENT KILL