version 1.4.2.1, 2022/09/15 15:04:44
|
version 1.4.2.3, 2022/09/15 15:48:41
|
Line 89 mqtt_KeepAlive(int sock, u_short ka, u_char tries)
|
Line 89 mqtt_KeepAlive(int sock, u_short ka, u_char tries)
|
if (sock < 3) |
if (sock < 3) |
return -1; /* error */ |
return -1; /* error */ |
|
|
if (mqtt_wait4data(sock, ka, POLLOUT)) | if ((ret = mqtt_wait4data(sock, ka, POLLOUT))) |
return ret; |
return ret; |
/* ping request */ |
/* ping request */ |
if (!(msg = mqtt_msgPINGREQ())) |
if (!(msg = mqtt_msgPINGREQ())) |
Line 109 mqtt_KeepAlive(int sock, u_short ka, u_char tries)
|
Line 109 mqtt_KeepAlive(int sock, u_short ka, u_char tries)
|
} |
} |
/* receive & decode packet */ |
/* receive & decode packet */ |
msg = mqtt_msgAlloc(BUFSIZ); |
msg = mqtt_msgAlloc(BUFSIZ); |
|
if (!msg) { |
|
ret = -1; |
|
break; |
|
} |
if ((ret = recv(sock, msg->msg_base, msg->msg_len, 0)) == -1) { |
if ((ret = recv(sock, msg->msg_base, msg->msg_len, 0)) == -1) { |
LOGERR; |
LOGERR; |
break; |
break; |
} |
} |
if (!mqtt_readPINGRESP(&msg)) { | if (!mqtt_readPINGRESP(msg)) { |
ret = 0; /* Host is alive */ |
ret = 0; /* Host is alive */ |
break; |
break; |
} else |
} else |
ret = 2; /* Session is broken ... must be disconnect! */ |
ret = 2; /* Session is broken ... must be disconnect! */ |
|
mqtt_msgFree(&msg, 0); |
} |
} |
end: |
end: |
mqtt_msgFree(&msg, 0); |
mqtt_msgFree(&msg, 0); |
return ret; |
return ret; |
} |
} |
|
|
#if 0 |
|
/* |
/* |
* mqtt_WillMessage() - Publish WILL message |
* mqtt_WillMessage() - Publish WILL message |
* |
* |
Line 138 int
|
Line 142 int
|
mqtt_WillMessage(int sock, u_short ka, const char *topic, const char *data) |
mqtt_WillMessage(int sock, u_short ka, const char *topic, const char *data) |
{ |
{ |
int ret = 0; |
int ret = 0; |
mqtt_msg_t msg = { NULL, 0 }; | mqtt_msg_t *msg = NULL; |
|
|
if (!topic) |
if (!topic) |
return -1; /* error */ |
return -1; /* error */ |
Line 146 mqtt_WillMessage(int sock, u_short ka, const char *top
|
Line 150 mqtt_WillMessage(int sock, u_short ka, const char *top
|
/* will message */ |
/* will message */ |
if ((ret = mqtt_wait4data(sock, ka, POLLOUT))) |
if ((ret = mqtt_wait4data(sock, ka, POLLOUT))) |
return ret; |
return ret; |
ret = mqtt_msgPUBLISH(&msg, topic, 0xDEAD, 0, 1, 0, data, data ? strlen(data) : 0); | msg = mqtt_msgPUBLISH(topic, 0xDEAD, 0, 1, 0, data, data ? strlen(data) : 0); |
if (ret == -1) | if (!msg) |
return -1; /* error */ |
return -1; /* error */ |
if ((ret = send(sock, msg.msg_base, ret, MSG_NOSIGNAL)) == -1) { | if ((ret = send(sock, msg->msg_base, msg->msg_len, MSG_NOSIGNAL)) == -1) { |
LOGERR; |
LOGERR; |
free(msg.msg_base); | mqtt_msgFree(&msg, 0); |
return -1; /* error */ |
return -1; /* error */ |
} else |
} else |
memset(msg.msg_base, 0, msg.msg_len); | mqtt_msgFree(&msg, 0); |
|
|
/* will ack */ |
/* will ack */ |
if ((ret = mqtt_wait4data(sock, ka, POLLIN | POLLPRI))) { | if ((ret = mqtt_wait4data(sock, ka, POLLIN | POLLPRI))) |
free(msg.msg_base); | |
return ret; |
return ret; |
} |
|
/* receive & decode packet */ |
/* receive & decode packet */ |
if ((ret = recv(sock, msg.msg_base, msg.msg_len, 0)) == -1) { | msg = mqtt_msgAlloc(BUFSIZ); |
| if (!msg) |
| return -1; |
| if ((ret = recv(sock, msg->msg_base, msg->msg_len, 0)) == -1) { |
LOGERR; |
LOGERR; |
free(msg.msg_base); | mqtt_msgFree(&msg, 0); |
return -1; /* error */ |
return -1; /* error */ |
} |
} |
if (mqtt_readPUBACK(&msg)) | if (mqtt_readPUBACK(msg)) |
ret = 0; /* ok */ |
ret = 0; /* ok */ |
else |
else |
ret = 2; /* semi-error */ |
ret = 2; /* semi-error */ |
|
mqtt_msgFree(&msg, 0); |
|
|
free(msg.msg_base); |
|
return ret; |
return ret; |
} |
} |
#endif |
|