mirror of https://github.com/eclipse/paho.mqtt.c
Merge branch 'develop' of github.com:eclipse/paho.mqtt.c into develop
This commit is contained in:
commit
7a5a5ae225
|
|
@ -55,7 +55,7 @@ SET(common_src
|
|||
)
|
||||
|
||||
IF (WIN32)
|
||||
SET(LIBS_SYSTEM ws2_32)
|
||||
SET(LIBS_SYSTEM ws2_32 crypt32 RpcRT4)
|
||||
ELSEIF (UNIX)
|
||||
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
SET(LIBS_SYSTEM c dl pthread anl)
|
||||
|
|
|
|||
|
|
@ -452,36 +452,42 @@ void MQTTAsync_sleep(long milliseconds)
|
|||
// http://ee.lbl.gov/papers/sync_94.pdf
|
||||
int MQTTAsync_randomJitter(int currentIntervalBase, int minInterval, int maxInterval)
|
||||
{
|
||||
int max_sleep = (int)min(maxInterval, currentIntervalBase) * 1.2; // (e.g. 72 if base > 60)
|
||||
int min_sleep = (int)max(minInterval, currentIntervalBase) / 1.2; // (e.g. 48 if base > 60)
|
||||
const int max_sleep = (int)(min(maxInterval, currentIntervalBase) * 1.2); // (e.g. 72 if base > 60)
|
||||
const int min_sleep = (int)(max(minInterval, currentIntervalBase) / 1.2); // (e.g. 48 if base > 60)
|
||||
|
||||
if (min_sleep >= max_sleep) // shouldn't happen, but just incase
|
||||
{
|
||||
return min_sleep;
|
||||
}
|
||||
|
||||
// random_between(min_sleep, max_sleep)
|
||||
// http://stackoverflow.com/questions/2509679/how-to-generate-a-random-number-from-within-a-range
|
||||
int r;
|
||||
int range = max_sleep - min_sleep + 1;
|
||||
if (range > RAND_MAX)
|
||||
{
|
||||
range = RAND_MAX;
|
||||
// random_between(min_sleep, max_sleep)
|
||||
// http://stackoverflow.com/questions/2509679/how-to-generate-a-random-number-from-within-a-range
|
||||
int r;
|
||||
int range = max_sleep - min_sleep + 1;
|
||||
if (range > RAND_MAX)
|
||||
{
|
||||
range = RAND_MAX;
|
||||
}
|
||||
|
||||
{
|
||||
const int buckets = RAND_MAX / range;
|
||||
const int limit = buckets * range;
|
||||
|
||||
/* Create equal size buckets all in a row, then fire randomly towards
|
||||
* the buckets until you land in one of them. All buckets are equally
|
||||
* likely. If you land off the end of the line of buckets, try again. */
|
||||
do
|
||||
{
|
||||
r = rand();
|
||||
} while (r >= limit);
|
||||
|
||||
{
|
||||
const int randResult = r / buckets;
|
||||
return min_sleep + randResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int buckets = RAND_MAX / range;
|
||||
int limit = buckets * range;
|
||||
|
||||
/* Create equal size buckets all in a row, then fire randomly towards
|
||||
* the buckets until you land in one of them. All buckets are equally
|
||||
* likely. If you land off the end of the line of buckets, try again. */
|
||||
do
|
||||
{
|
||||
r = rand();
|
||||
} while (r >= limit);
|
||||
|
||||
int randResult = r / buckets;
|
||||
return min_sleep + randResult;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1521,7 +1521,7 @@ MQTTResponse MQTTClient_connectAll(MQTTClient handle, MQTTClient_connectOptions*
|
|||
int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
|
||||
{
|
||||
MQTTClients* m = handle;
|
||||
MQTTResponse response;
|
||||
MQTTResponse response;
|
||||
|
||||
if (m->c->MQTTVersion >= MQTTVERSION_5)
|
||||
return MQTTCLIENT_WRONG_MQTT_VERSION;
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ int MQTTPersistence_restore(Clients *c)
|
|||
{
|
||||
int data_MQTTVersion = MQTTVERSION_3_1_1;
|
||||
char* cur_key = msgkeys[i];
|
||||
MQTTPacket* pack = NULL;
|
||||
MQTTPacket* pack = NULL;
|
||||
|
||||
if ( strncmp(cur_key, PERSISTENCE_V5_PUBLISH_RECEIVED,
|
||||
strlen(PERSISTENCE_V5_PUBLISH_RECEIVED)) == 0)
|
||||
|
|
|
|||
|
|
@ -525,14 +525,16 @@ static unsigned int call_ssl_psk_cb(SSL *ssl, const char *hint, char *identity,
|
|||
|
||||
FUNC_ENTRY;
|
||||
|
||||
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
||||
MQTTClient_SSLOptions* opts = SSL_CTX_get_ex_data(ctx, tls_ex_index_ssl_opts);
|
||||
{
|
||||
SSL_CTX *ctx = SSL_get_SSL_CTX(ssl);
|
||||
MQTTClient_SSLOptions* opts = SSL_CTX_get_ex_data(ctx, tls_ex_index_ssl_opts);
|
||||
|
||||
if (opts == NULL)
|
||||
goto exit;
|
||||
if (opts == NULL)
|
||||
goto exit;
|
||||
|
||||
if (opts->ssl_psk_cb != NULL)
|
||||
rc = opts->ssl_psk_cb(hint, identity, max_identity_len, psk, max_psk_len, opts->ssl_psk_context);
|
||||
if (opts->ssl_psk_cb != NULL)
|
||||
rc = opts->ssl_psk_cb(hint, identity, max_identity_len, psk, max_psk_len, opts->ssl_psk_context);
|
||||
}
|
||||
exit:
|
||||
FUNC_EXIT_RC(rc);
|
||||
return rc;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#include <errno.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#define MAXHOSTNAMELEN 256
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@
|
|||
# pragma comment(lib, "rpcrt4.lib")
|
||||
# include <Rpc.h>
|
||||
# define strncasecmp(s1,s2,c) _strnicmp(s1,s2,c)
|
||||
# define htonll(x) _byteswap_uint64(x)
|
||||
# define ntohll(x) _byteswap_uint64(x)
|
||||
|
||||
# if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define htobe16(x) htons(x)
|
||||
# define htobe32(x) htonl(x)
|
||||
|
|
@ -62,14 +65,15 @@
|
|||
# else
|
||||
# error "unknown endian"
|
||||
# endif
|
||||
/* For Microsoft Visual Studio 2013 */
|
||||
# if !defined( snprintf )
|
||||
/* For Microsoft Visual Studio < 2015 */
|
||||
# if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
# endif /* if !defined( snprintf ) */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL)
|
||||
#include "SSLSocket.h"
|
||||
#include <openssl/rand.h>
|
||||
#endif /* defined(OPENSSL) */
|
||||
#include "Socket.h"
|
||||
|
||||
|
|
@ -81,10 +85,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(OPENSSL)
|
||||
#include <openssl/rand.h>
|
||||
#endif /* if defined(OPENSSL) */
|
||||
|
||||
#include "Heap.h"
|
||||
|
||||
/** @brief raw uuid type */
|
||||
|
|
@ -657,7 +657,7 @@ char *WebSocket_getRawSocketData(
|
|||
frame_buffer = NULL;
|
||||
}
|
||||
// append data to the buffer
|
||||
else if (rv != NULL)
|
||||
else if (rv != NULL && *actual_len != 0U)
|
||||
{
|
||||
// no buffer allocated
|
||||
if (!frame_buffer)
|
||||
|
|
|
|||
Loading…
Reference in New Issue