mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-13 16:35:35 +08:00
Merge branch 'gitee-master' into gitlab-upstream
This commit is contained in:
commit
f5c8107381
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -79,7 +87,7 @@ 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) {
|
||||
@ -87,7 +95,7 @@ int main(int argc, char *argv[])
|
||||
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);
|
||||
@ -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;
|
||||
@ -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:
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
@ -78,8 +80,17 @@ static void load_servers(std::vector<acl::string>& servers, const char* f)
|
||||
if (!fp.gets(buf)) {
|
||||
break;
|
||||
}
|
||||
if (acl_valid_ipv6_hostaddr(buf.c_str(), 0)) {
|
||||
printf("Valid IPv6 addr=%s\r\n", buf.c_str());
|
||||
} else {
|
||||
printf("Invalid IPv6 addr=%s\r\n", buf.c_str());
|
||||
}
|
||||
servers.push_back(buf);
|
||||
}
|
||||
|
||||
printf("Enter any key to continue...");
|
||||
fflush(stdout);
|
||||
getchar();
|
||||
}
|
||||
|
||||
static void usage(const char* procname)
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -64,5 +64,6 @@
|
||||
#define ACL_CPP_DEBUG_MIN 40
|
||||
#define ACL_CPP_DEBUG_CONN_MANAGER 41
|
||||
#define ACL_CPP_DEBUG_HTTP_NET 42
|
||||
#define DEBUG_MQTT 43
|
||||
#define ACL_CPP_DEBUG_MAX 70
|
||||
|
||||
|
@ -102,18 +102,19 @@ bool mqtt_client::read_header(mqtt_header& header) {
|
||||
|
||||
// update the first char for mqtt_type_t
|
||||
if (header.update(&ch, 1) != 0) {
|
||||
logger_error("invalid header type=%d", (int) ch);
|
||||
logger_debug(DEBUG_MQTT, 1, "invalid header type=%d", (int) ch);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!conn_->read(ch)) {
|
||||
logger_error("read one char error: %s, i=%d",
|
||||
logger_debug(DEBUG_MQTT, 1, "read char error: %s, i=%d",
|
||||
last_serror(), i);
|
||||
return false;
|
||||
}
|
||||
if (header.update(&ch, 1) != 0) {
|
||||
logger_error("header_update error, ch=%d", (int) ch);
|
||||
logger_debug(DEBUG_MQTT, 1, "header_update error, ch=%d",
|
||||
(int) ch);
|
||||
return false;
|
||||
}
|
||||
if (header.finished()) {
|
||||
@ -122,7 +123,7 @@ bool mqtt_client::read_header(mqtt_header& header) {
|
||||
}
|
||||
|
||||
if (!header.finished()) {
|
||||
logger_error("get mqtt header error");
|
||||
logger_debug(DEBUG_MQTT, 1, "get mqtt header error");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -140,7 +141,8 @@ bool mqtt_client::read_message(const mqtt_header& header, mqtt_message& body) {
|
||||
size_t size = sizeof(buf) > len ? len : sizeof(buf);
|
||||
int n = conn_->read(buf, size);
|
||||
if (n == -1) {
|
||||
logger_error("read body error: %s", last_serror());
|
||||
logger_debug(DEBUG_MQTT, 1, "read body error: %s",
|
||||
last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -148,16 +150,16 @@ bool mqtt_client::read_message(const mqtt_header& header, mqtt_message& body) {
|
||||
|
||||
n = body.update(buf, (int) size);
|
||||
if (n == -1) {
|
||||
logger_error("update body error");
|
||||
logger_debug(DEBUG_MQTT, 1, "update body error");
|
||||
return false;
|
||||
} else if (n != 0) {
|
||||
logger_error("invalid body data");
|
||||
logger_debug(DEBUG_MQTT, 1, "invalid body data");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!body.finished()) {
|
||||
logger_error("body not finished!");
|
||||
logger_debug(DEBUG_MQTT, 1, "body not finished!");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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();
|
||||
|
@ -90,7 +90,7 @@ static unsigned to_oflags(unsigned flags)
|
||||
return oflags;
|
||||
}
|
||||
|
||||
bool socket_stream::bind_udp(const char* addr, int rw_timeout /* = 0 */,
|
||||
bool socket_stream::bind_udp(const char* addr, int rw_timeout /* = -1 */,
|
||||
unsigned flags /* = 0 */)
|
||||
{
|
||||
if (stream_) {
|
||||
|
Loading…
Reference in New Issue
Block a user