Skip to content

Commit 53d4fb9

Browse files
formatting, spelling fix, rename DNS support macro guard
1 parent 954ad42 commit 53d4fb9

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

examples/mqttnet.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -412,28 +412,29 @@ static int NetConnect(void *context, const char* host, word16 port,
412412
PRINTF("NetConnect: Host %s, Port %u, Timeout %d ms, "
413413
"Use TLS %d", host, port, timeout_ms, mqttCtx->use_tls);
414414
}
415-
#ifdef HAVE_NETX_DNS
415+
#ifndef WOLFMQTT_NO_NETX_DNS
416416
/* Convert hostname to IP address using NETX DUO DNS */
417-
status = nxd_dns_host_by_name_get(sock->ipPtr, (UCHAR *)host, &ipAddress, timeout_ms);
417+
status = nxd_dns_host_by_name_get(sock->ipPtr, (UCHAR *)host,
418+
&ipAddress, timeout_ms);
418419
if (status != NX_SUCCESS) {
419420
PRINTF("DNS lookup failed: %d", status);
420421
return MQTT_CODE_ERROR_NETWORK;
421422
}
422423
#else
423-
PRINTF("DNS lookup not avilable");
424-
return MQTT_CODE_ERROR_NETWORK;
424+
PRINTF("DNS lookup not available");
425+
return MQTT_CODE_ERROR_NETWORK;
425426
#endif
426-
status = nx_tcp_socket_create(sock->ipPtr, &sock->fd,
427-
"MQTT Socket", NX_IP_NORMAL,
428-
NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE,
429-
1024, NX_NULL, NX_NULL);
427+
status = nx_tcp_socket_create(sock->ipPtr, &sock->fd,
428+
"MQTT Socket", NX_IP_NORMAL,
429+
NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE,
430+
1024, NX_NULL, NX_NULL);
430431
if (status != NX_SUCCESS) {
431432
PRINTF("Socket create failed: %d", status);
432433
return MQTT_CODE_ERROR_NETWORK;
433434
}
434435

435436
/* Bind the socket to a local port */
436-
status = nx_tcp_client_socket_bind(&sock->fd, port, NX_WAIT_FOREVER);
437+
status = nx_tcp_client_socket_bind(&sock->fd, port, timeout_ms);
437438
if (status != NX_SUCCESS) {
438439
PRINTF("Socket bind failed: %d", status);
439440
return MQTT_CODE_ERROR_NETWORK;
@@ -446,11 +447,9 @@ static int NetConnect(void *context, const char* host, word16 port,
446447
case SOCK_CONN:
447448
{
448449
/* Connect to server using NETX DUO */
449-
status = nxd_tcp_client_socket_connect(&sock->fd, &ipAddress, port, timeout_ms);
450+
status = nxd_tcp_client_socket_connect(&sock->fd, &ipAddress, port,
451+
timeout_ms);
450452
if (status != NX_SUCCESS) {
451-
if (status == NX_WAIT_ABORTED) {
452-
return MQTT_CODE_CONTINUE;
453-
}
454453
PRINTF("Socket connect failed: %d", status);
455454
NetDisconnect(context);
456455
return MQTT_CODE_ERROR_NETWORK;
@@ -467,8 +466,7 @@ static int NetConnect(void *context, const char* host, word16 port,
467466
}
468467

469468

470-
static int NetWrite(void *context, const byte* buf, int buf_len,
471-
int timeout_ms)
469+
static int NetWrite(void *context, const byte* buf, int buf_len, int timeout_ms)
472470
{
473471
SocketContext *sock = (SocketContext*)context;
474472
NX_PACKET* packet;
@@ -481,14 +479,14 @@ static int NetWrite(void *context, const byte* buf, int buf_len,
481479
}
482480

483481
pool = sock->fd.nx_tcp_socket_ip_ptr->nx_ip_default_packet_pool;
484-
status = nx_packet_allocate(pool, &packet, NX_TCP_PACKET,
485-
timeout_ms);
482+
status = nx_packet_allocate(pool, &packet, NX_TCP_PACKET, timeout_ms);
486483
if (status != NX_SUCCESS) {
487484
PRINTF("NetX Send packet alloc error");
488485
return MQTT_CODE_ERROR_NETWORK;
489486
}
490487

491-
status = nx_packet_data_append(packet, (VOID*)buf, buf_len, pool, timeout_ms);
488+
status = nx_packet_data_append(packet, (VOID*)buf, buf_len, pool,
489+
timeout_ms);
492490
if (status != NX_SUCCESS) {
493491
nx_packet_release(packet);
494492
PRINTF("NetX Send data append error");
@@ -506,8 +504,7 @@ static int NetWrite(void *context, const byte* buf, int buf_len,
506504
}
507505

508506

509-
static int NetRead(void *context, byte* buf, int buf_len,
510-
int timeout_ms)
507+
static int NetRead(void *context, byte* buf, int buf_len, int timeout_ms)
511508
{
512509
SocketContext *sock = (SocketContext*)context;
513510
ULONG left;
@@ -521,8 +518,7 @@ static int NetRead(void *context, byte* buf, int buf_len,
521518
}
522519

523520
if (sock->nxPacket == NULL) {
524-
status = nx_tcp_socket_receive(&sock->fd, &sock->nxPacket,
525-
timeout_ms);
521+
status = nx_tcp_socket_receive(&sock->fd, &sock->nxPacket, timeout_ms);
526522
if (status != NX_SUCCESS) {
527523
PRINTF("NetX Recv receive error");
528524
return MQTT_CODE_ERROR_NETWORK;
@@ -537,8 +533,8 @@ static int NetRead(void *context, byte* buf, int buf_len,
537533
}
538534

539535
left = total - sock->nxOffset;
540-
status = nx_packet_data_extract_offset(sock->nxPacket, sock->nxOffset,
541-
buf, buf_len, &copied);
536+
status = nx_packet_data_extract_offset(sock->nxPacket,
537+
sock->nxOffset, buf, buf_len, &copied);
542538
if (status != NX_SUCCESS) {
543539
PRINTF("NetX Recv data extract offset error");
544540
return MQTT_CODE_ERROR_NETWORK;

0 commit comments

Comments
 (0)