@@ -219,6 +219,20 @@ static int NetDisconnect(void *context)
219
219
/* -------------------------------------------------------------------------- */
220
220
#elif defined(MICROCHIP_MPLAB_HARMONY )
221
221
222
+ static int NetDisconnect (void * context )
223
+ {
224
+ SocketContext * sock = (SocketContext * )context ;
225
+ if (sock ) {
226
+ if (sock -> fd != SOCKET_INVALID ) {
227
+ closesocket (sock -> fd );
228
+ sock -> fd = SOCKET_INVALID ;
229
+ }
230
+
231
+ sock -> stat = SOCK_BEGIN ;
232
+ }
233
+ return 0 ;
234
+ }
235
+
222
236
static int NetConnect (void * context , const char * host , word16 port ,
223
237
int timeout_ms )
224
238
{
@@ -287,6 +301,7 @@ static int NetConnect(void *context, const char* host, word16 port,
287
301
if (errno == EINPROGRESS || errno == EWOULDBLOCK ) {
288
302
return MQTT_CODE_CONTINUE ;
289
303
}
304
+ NetDisconnect (context );
290
305
291
306
/* Show error */
292
307
PRINTF ("NetConnect: Rc=%d, ErrNo=%d" , rc , errno );
@@ -358,20 +373,6 @@ static int NetRead(void *context, byte* buf, int buf_len,
358
373
return rc ;
359
374
}
360
375
361
- static int NetDisconnect (void * context )
362
- {
363
- SocketContext * sock = (SocketContext * )context ;
364
- if (sock ) {
365
- if (sock -> fd != SOCKET_INVALID ) {
366
- closesocket (sock -> fd );
367
- sock -> fd = SOCKET_INVALID ;
368
- }
369
-
370
- sock -> stat = SOCK_BEGIN ;
371
- }
372
- return 0 ;
373
- }
374
-
375
376
/* -------------------------------------------------------------------------- */
376
377
/* GENERIC BSD SOCKET TCP NETWORK CALLBACK EXAMPLE */
377
378
/* -------------------------------------------------------------------------- */
@@ -410,6 +411,20 @@ static void tcp_set_nonblocking(SOCKET_T* sockfd)
410
411
#endif /* WOLFMQTT_NONBLOCK */
411
412
#endif /* !WOLFMQTT_NO_TIMEOUT */
412
413
414
+ static int NetDisconnect (void * context )
415
+ {
416
+ SocketContext * sock = (SocketContext * )context ;
417
+ if (sock ) {
418
+ if (sock -> fd != SOCKET_INVALID ) {
419
+ SOCK_CLOSE (sock -> fd );
420
+ sock -> fd = SOCKET_INVALID ;
421
+ }
422
+
423
+ sock -> stat = SOCK_BEGIN ;
424
+ }
425
+ return 0 ;
426
+ }
427
+
413
428
static int NetConnect (void * context , const char * host , word16 port ,
414
429
int timeout_ms )
415
430
{
@@ -539,9 +554,9 @@ static int NetConnect(void *context, const char* host, word16 port,
539
554
(void )timeout_ms ;
540
555
541
556
exit :
542
- /* Show error */
543
- if ( rc != 0 ) {
544
- PRINTF ("NetConnect: Rc=%d, SoErr=%d" , rc , so_error );
557
+ if (( rc != 0 ) && ( rc != MQTT_CODE_CONTINUE )) {
558
+ NetDisconnect ( context );
559
+ PRINTF ("NetConnect: Rc=%d, SoErr=%d" , rc , so_error ); /* Show error */
545
560
}
546
561
547
562
return rc ;
@@ -630,8 +645,8 @@ static int SN_NetConnect(void *context, const char* host, word16 port,
630
645
631
646
exit :
632
647
/* Show error */
633
- if (rc != 0 ) {
634
- SOCK_CLOSE ( sock -> fd );
648
+ if (( rc != 0 ) && ( rc != MQTT_CODE_CONTINUE ) ) {
649
+ NetDisconnect ( context );
635
650
PRINTF ("NetConnect: Rc=%d, SoErr=%d" , rc , so_error );
636
651
}
637
652
@@ -873,20 +888,6 @@ static int NetPeek(void *context, byte* buf, int buf_len, int timeout_ms)
873
888
}
874
889
#endif
875
890
876
- static int NetDisconnect (void * context )
877
- {
878
- SocketContext * sock = (SocketContext * )context ;
879
- if (sock ) {
880
- if (sock -> fd != SOCKET_INVALID ) {
881
- SOCK_CLOSE (sock -> fd );
882
- sock -> fd = -1 ;
883
- }
884
-
885
- sock -> stat = SOCK_BEGIN ;
886
- }
887
- return 0 ;
888
- }
889
-
890
891
#endif
891
892
892
893
0 commit comments