Skip to content

Commit 0079a51

Browse files
committed
FIX libmosquitto inflight_messages counter when reconnect
FIX MQTTKit remove handlers on disconnect
1 parent da692e6 commit 0079a51

4 files changed

Lines changed: 21 additions & 42 deletions

File tree

MQTTKit/MQTTKit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ typedef void (^MQTTDisconnectionHandler)(NSUInteger code);
7373
- (MQTTClient*) initWithClientId: (NSString *)clientId
7474
cleanSession: (BOOL )cleanSession;
7575

76+
- (void) destroy;
77+
7678
- (void) setMaxInflightMessages:(NSUInteger)maxInflightMessages;
7779
- (void) setMessageRetry: (NSUInteger)seconds;
7880

MQTTKit/MQTTKit.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "MQTTKit.h"
1111
#import "mosquitto.h"
1212

13-
#if 0 // set to 1 to enable logs
13+
#if 1 // set to 1 to enable logs
1414

1515
#define LogDebug(frmt, ...) NSLog(frmt, ##__VA_ARGS__);
1616

@@ -92,9 +92,9 @@ static void on_disconnect(struct mosquitto *mosq, void *obj, int rc)
9292
{
9393
MQTTClient* client = (__bridge MQTTClient*)obj;
9494
LogDebug(@"[%@] on_disconnect rc = %d", client.clientID, rc);
95-
[client.publishHandlers removeAllObjects];
96-
[client.subscriptionHandlers removeAllObjects];
97-
[client.unsubscriptionHandlers removeAllObjects];
95+
// [client.publishHandlers removeAllObjects];
96+
// [client.subscriptionHandlers removeAllObjects];
97+
// [client.unsubscriptionHandlers removeAllObjects];
9898

9999
client.connected = NO;
100100
if (client.disconnectionHandler) {
@@ -216,6 +216,14 @@ - (MQTTClient*) initWithClientId: (NSString *)clientId
216216
return self;
217217
}
218218

219+
- (void) destroy
220+
{
221+
if (mosq) {
222+
mosquitto_destroy(mosq);
223+
mosq = NULL;
224+
}
225+
}
226+
219227
- (void) setMaxInflightMessages:(NSUInteger)maxInflightMessages
220228
{
221229
mosquitto_max_inflight_messages_set(mosq, (unsigned int)maxInflightMessages);
@@ -226,11 +234,9 @@ - (void) setMessageRetry: (NSUInteger)seconds
226234
mosquitto_message_retry_set(mosq, (unsigned int)seconds);
227235
}
228236

229-
- (void) dealloc {
230-
if (mosq) {
231-
mosquitto_destroy(mosq);
232-
mosq = NULL;
233-
}
237+
- (void) dealloc
238+
{
239+
[self destroy];
234240
}
235241

236242
#pragma mark - Connection
@@ -255,7 +261,7 @@ - (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))c
255261
}
256262
// add tls insecure set
257263
mosquitto_tls_insecure_set(mosq, self.tlsInsecure);
258-
mosquitto_tls_opts_set(mosq,0,"tlsv1",nil);
264+
mosquitto_tls_opts_set(mosq,1,"tlsv1",nil);
259265

260266
mosquitto_connect(mosq, cstrHost, self.port, self.keepAlive);
261267

libmosquitto/messages_mosq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq)
147147
message->timestamp = 0;
148148
if(message->direction == mosq_md_out){
149149
mosq->queue_len++;
150-
if(message->msg.qos > 0){
151-
mosq->inflight_messages++;
152-
}
153150
if(mosq->max_inflight_messages == 0 || mosq->inflight_messages < mosq->max_inflight_messages){
151+
if(message->msg.qos > 0){
152+
mosq->inflight_messages++;
153+
}
154154
if(message->msg.qos == 1){
155155
message->state = mosq_ms_wait_for_puback;
156156
}else if(message->msg.qos == 2){

libmosquitto/tls_mosq.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,6 @@ int _mosquitto_server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx)
5959

6060
/* Always reject if preverify_ok has failed. */
6161
if(!preverify_ok) return 0;
62-
{
63-
char buf[256];
64-
int err, depth;
65-
cert = X509_STORE_CTX_get_current_cert(ctx);
66-
err = X509_STORE_CTX_get_error(ctx);
67-
depth = X509_STORE_CTX_get_error_depth(ctx);
68-
X509_NAME_oneline(X509_get_subject_name(cert), buf, 256);
69-
70-
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
71-
long result = SSL_get_verify_result(ssl);
72-
73-
X509 *brokerCert = SSL_get_peer_certificate(ssl);
74-
75-
const char *dir;
76-
77-
dir = getenv(X509_get_default_cert_dir_env());
78-
79-
if (!dir)
80-
dir = X509_get_default_cert_dir();
81-
82-
printf("verify error:num=%d:%s:depth=%d:%s\n", err,
83-
X509_verify_cert_error_string(err), depth, buf);
84-
//return 0;
85-
86-
if (err == 18)
87-
{
88-
return 1;
89-
}
90-
}
9162

9263
ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
9364
mosq = SSL_get_ex_data(ssl, tls_ex_index_mosq);

0 commit comments

Comments
 (0)