mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-02 20:08:21 +08:00
test mqtt
This commit is contained in:
parent
f36280c854
commit
ab0ae2777a
@ -55,9 +55,10 @@ static bool handle_publish(acl::mqtt_client& conn,
|
|||||||
const acl::mqtt_message& message) {
|
const acl::mqtt_message& message) {
|
||||||
const acl::mqtt_publish& publish = (const acl::mqtt_publish&) message;
|
const acl::mqtt_publish& publish = (const acl::mqtt_publish&) message;
|
||||||
const acl::string& payload = publish.get_payload();
|
const acl::string& payload = publish.get_payload();
|
||||||
printf("topic: %s, qos: %d, pkt_id: %d, payload len: %zd, payload: %s\r\n",
|
printf("payload: %s\r\n", payload.c_str());
|
||||||
|
printf("topic: %s, qos: %d, pkt_id: %d, payload len: %zd\r\n",
|
||||||
publish.get_topic(), (int) publish.get_header().get_qos(),
|
publish.get_topic(), (int) publish.get_header().get_qos(),
|
||||||
publish.get_pkt_id(), payload.size(), payload.c_str());
|
publish.get_pkt_id(), payload.size());
|
||||||
|
|
||||||
if (publish.get_header().get_qos() == acl::MQTT_QOS0) {
|
if (publish.get_header().get_qos() == acl::MQTT_QOS0) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -14,7 +14,7 @@ static bool handle_puback(acl::mqtt_client&, const acl::mqtt_message&) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool test_publish(acl::mqtt_client& conn, unsigned short id) {
|
static bool test_publish(acl::mqtt_client& conn, unsigned short id, int length) {
|
||||||
acl::mqtt_publish publish;
|
acl::mqtt_publish publish;
|
||||||
|
|
||||||
publish.get_header().set_qos(acl::MQTT_QOS1);
|
publish.get_header().set_qos(acl::MQTT_QOS1);
|
||||||
@ -24,7 +24,12 @@ static bool test_publish(acl::mqtt_client& conn, unsigned short id) {
|
|||||||
publish.set_topic(topic);
|
publish.set_topic(topic);
|
||||||
|
|
||||||
acl::string payload;
|
acl::string payload;
|
||||||
payload.format("payload-%ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", id);
|
payload.format("payload-%d:", id);
|
||||||
|
|
||||||
|
for (; payload.size() < (size_t) length;) {
|
||||||
|
payload += 'c';
|
||||||
|
}
|
||||||
|
|
||||||
publish.set_payload((unsigned) payload.size(), payload);
|
publish.set_payload((unsigned) payload.size(), payload);
|
||||||
|
|
||||||
if (!conn.send(publish)) {
|
if (!conn.send(publish)) {
|
||||||
@ -64,15 +69,15 @@ static bool test_publish(acl::mqtt_client& conn, unsigned short id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void usage(const char* procname) {
|
static void usage(const char* procname) {
|
||||||
printf("usage: %s -h [help] -s addr -n max\r\n", procname);
|
printf("usage: %s -h [help] -s addr -n max -c payload_length\r\n", procname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
char ch;
|
char ch;
|
||||||
int max = 1;
|
int max = 1, length = 32;
|
||||||
acl::string addr("127.0.0.1|1883");
|
acl::string addr("127.0.0.1|1883");
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "hs:n:")) > 0) {
|
while ((ch = getopt(argc, argv, "hs:n:c:")) > 0) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
@ -83,6 +88,9 @@ int main(int argc, char* argv[]) {
|
|||||||
case 'n':
|
case 'n':
|
||||||
max = atoi(optarg);
|
max = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
length = atoi(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -126,7 +134,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
unsigned short id = 1;
|
unsigned short id = 1;
|
||||||
for (int i = 1; i <= max; i++) {
|
for (int i = 1; i <= max; i++) {
|
||||||
if (!test_publish(conn, id++)) {
|
if (!test_publish(conn, id++, length)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// id must be more than 0
|
// id must be more than 0
|
||||||
|
Loading…
Reference in New Issue
Block a user