Skip to content

Commit

Permalink
Test coder demo.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin committed Dec 26, 2023
1 parent 2f42289 commit 72feade
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib_acl/samples/coder/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void b64_encode(const char *ptr)
acl_vstring_free(str);
}

static void b64_decode(const char *ptr)
static void b64_decode(const char *ptr, int verbose)
{
ACL_VSTRING *str = acl_vstring_alloc(1);
const char *p;
Expand All @@ -29,10 +29,17 @@ static void b64_decode(const char *ptr)
DECODE(str, ptr, strlen(ptr));

p = acl_vstring_str(str);
printf(">>>decode result:|%s|\n>>>orignal str: {%s}, len: %d\n",
p, ptr, (int) ACL_VSTRING_LEN(str));
b64_encode(p);
printf("len: %d, %d\n", (int) ACL_VSTRING_LEN(str), (int) strlen(p));
if (verbose) {
printf(">>>decode result:|%s|\n>>>orignal str: {%s}, len: %d\n",
p, ptr, (int) ACL_VSTRING_LEN(str));
} else {
printf("%s\n", p);
}

if (verbose) {
b64_encode(p);
printf("len: %d, %d\n", (int) ACL_VSTRING_LEN(str), (int) strlen(p));
}

acl_vstring_free(str);
}
Expand Down Expand Up @@ -70,6 +77,7 @@ static void usage(const char *prog)
printf("usage: %s -s string\r\n"
" -a action[default: encode, encode|decode]\r\n"
" -t type [default: base64, base64|bin|crc32]\r\n"
" -V [verbose]\r\n"
" -h help]\n", prog);
}

Expand All @@ -79,15 +87,15 @@ static void usage(const char *prog)

int main(int argc, char *argv[])
{
int ch, encode = 1, type = BASE64_TYPE;
int ch, encode = 1, type = BASE64_TYPE, verbose = 0;
char *buf = NULL;

if (argc == 1) {
usage(argv[0]);
exit (1);
}

while ((ch = getopt(argc, argv, "s:a:t:h")) > 0) {
while ((ch = getopt(argc, argv, "s:a:t:hV")) > 0) {
switch (ch) {
case 's':
buf = strdup(optarg);
Expand All @@ -107,6 +115,9 @@ int main(int argc, char *argv[])
case 'h':
usage(argv[0]);
return 0;
case 'V':
verbose = 1;
break;
default:
usage(argv[0]);
return 0;
Expand All @@ -124,7 +135,7 @@ int main(int argc, char *argv[])
if (encode) {
b64_encode(buf);
} else {
b64_decode(buf);
b64_decode(buf, verbose);
}
break;
case BIN_TYPE:
Expand Down
5 changes: 5 additions & 0 deletions lib_acl_cpp/src/redis/redis_client_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void redis_pipeline_channel::push(redis_pipeline_message* msg)
bool redis_pipeline_channel::flush_all(void)
{
if (msgs_.empty()) {
logger("The messages are empty!");
return true;
}

Expand Down Expand Up @@ -92,6 +93,7 @@ bool redis_pipeline_channel::flush_all(void)

// Return false if we have retried
if (retried) {
logger_error("Retried failed!");
return false;
}

Expand Down Expand Up @@ -253,6 +255,8 @@ bool redis_pipeline_channel::handle_messages(void)
return true;
}

logger_warn("wait results failed, try again!");

if (retried) {
logger_error("Retried failed");
break;
Expand All @@ -264,6 +268,7 @@ bool redis_pipeline_channel::handle_messages(void)
logger_error("Reopen failed");
break;
}
logger("Connection opened OK, addr=%s", client_->get_addr());
}

all_failed();
Expand Down

0 comments on commit 72feade

Please sign in to comment.