mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
Fix #1616 - randomize mqtt will and client id for parallel test
This commit is contained in:
1 parent
432452ea9a
commit
81ffcd8ee9
6 files changed
+52
-3
No files matched your search
+13
@@ -21,6 +21,19 @@ void mg_random(void *buf, size_t len) {
|
||||
}
|
||||
#endif
|
||||
|
||||
char *mg_random_str(char *buf, size_t len) {
|
||||
size_t i;
|
||||
mg_random(buf, len);
|
||||
for (i = 0; i < len; i++) {
|
||||
uint8_t c = ((uint8_t *) buf)[i] % 62;
|
||||
buf[i] = i == len - 1 ? '\0' // 0-terminate last byte
|
||||
: c < 26 ? (char) ('a' + c) // lowercase
|
||||
: c < 52 ? (char) ('A' + c - 26) // uppercase
|
||||
: (char) ('0' + c - 52); // numeric
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
uint32_t mg_ntohl(uint32_t net) {
|
||||
uint8_t data[4] = {0, 0, 0, 0};
|
||||
memcpy(&data, &net, sizeof(data));
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "str.h"
|
||||
|
||||
void mg_random(void *buf, size_t len);
|
||||
char *mg_random_str(char *buf, size_t len);
|
||||
uint16_t mg_ntohs(uint16_t net);
|
||||
uint32_t mg_ntohl(uint32_t net);
|
||||
uint32_t mg_crc32(uint32_t crc, const char *buf, size_t len);
|
||||
|
||||
Reference in new issue
Block a user