MQTTClient PublishMessage Bug [message #1737697] |
Tue, 12 July 2016 02:10  |
Eclipse User |
|
|
|
My configurations :
1- Keepaliveinterval=20
2- Timeout = 20000 msec
Addition code :
3- std::cout<<"Publish1:"<<std::endl;
int nReturn = MQTTClient_publishMessage( m_MqttClient, m_Topic.c_str(), &pubmsg, &token );
std::cout<<"Publish2:"<<std::endl;
When I plug out the ethernet cable, I can't see "Publish2" on the screen and the program stuck on exacly here.
I found the line where the code stuck when I plug off the ethernet cable. It is a part of MQTTClient.c. The code stuck on "printf("DEBUG2: %d\n",rc);" line and I don't see another thing on the screen. The Code:
int MQTTClient_publish(MQTTClient handle, const char* topicName, int payloadlen, void* payload,
int qos, int retained, MQTTClient_deliveryToken* deliveryToken)
{
printf("DEBUG1 \n");
int rc = MQTTCLIENT_SUCCESS;
MQTTClients* m = handle;
Messages* msg = NULL;
Publish* p = NULL;
int blocked = 0;
int msgid = 0;
FUNC_ENTRY;
printf("DEBUG2: %d\n",rc);
Thread_lock_mutex(mqttclient_mutex);
if (m == NULL || m->c == NULL)
rc = MQTTCLIENT_FAILURE;
else if (m->c->connected == 0)
rc = MQTTCLIENT_DISCONNECTED;
else if (!UTF8_validateString(topicName))
rc = MQTTCLIENT_BAD_UTF8_STRING;
if (rc != MQTTCLIENT_SUCCESS)
goto exit;
printf("DEBUG3:rc:,%d \n",rc);
/* If outbound queue is full, block until it is not */
while (m->c->outboundMsgs->count >= m->c->maxInflightMessages ||
Socket_noPendingWrites(m->c->net.socket) == 0) /* wait until the socket is free of large packets being written */
{
printf("DEBUG4:blocked: %d\n",blocked);
if (blocked == 0)
{
blocked = 1;
Log(TRACE_MIN, -1, "Blocking publish on queue full for client %s", m->c->clientID);
printf("DEBUG5:Blocking publish on queue full for client %s \n", m->c->clientID);
}
Thread_unlock_mutex(mqttclient_mutex);
MQTTClient_yield();
Thread_lock_mutex(mqttclient_mutex);
if (m->c->connected == 0)
{
rc = MQTTCLIENT_FAILURE;
goto exit;
}
}
if (blocked == 1)
Log(TRACE_MIN, -1, "Resuming publish now queue not full for client %s", m->c->clientID);
if (qos > 0 && (msgid = MQTTProtocol_assignMsgId(m->c)) == 0)
{ /* this should never happen as we've waited for spaces in the queue */
rc = MQTTCLIENT_MAX_MESSAGES_INFLIGHT;
printf("DEBUG6:rc:,%d \n",rc);
goto exit;
}
p = malloc(sizeof(Publish));
p->payload = payload;
p->payloadlen = payloadlen;
p->topic = (char*)topicName;
p->msgId = msgid;
rc = MQTTProtocol_startPublish(m->c, p, qos, retained, &msg);
/* If the packet was partially written to the socket, wait for it to complete.
* However, if the client is disconnected during this time and qos is not 0, still return success, as
* the packet has already been written to persistence and assigned a message id so will
* be sent when the client next connects.
*/
if (rc == TCPSOCKET_INTERRUPTED)
{
while (m->c->connected == 1 && SocketBuffer_getWrite(m->c->net.socket))
{
printf("DEBUG7:rc:,%d \n",rc);
Thread_unlock_mutex(mqttclient_mutex);
MQTTClient_yield();
Thread_lock_mutex(mqttclient_mutex);
printf("DEBUG8:rc:,%d \n",rc);
}
rc = (qos > 0 || m->c->connected == 1) ? MQTTCLIENT_SUCCESS : MQTTCLIENT_FAILURE;
}
if (deliveryToken && qos > 0)
*deliveryToken = msg->msgid;
free(p);
if (rc == SOCKET_ERROR)
{
Thread_unlock_mutex(mqttclient_mutex);
MQTTClient_disconnect_internal(handle, 0);
Thread_lock_mutex(mqttclient_mutex);
/* Return success for qos > 0 as the send will be retried automatically */
rc = (qos > 0) ? MQTTCLIENT_SUCCESS : MQTTCLIENT_FAILURE;
}
exit:
printf("DEBUG8.5:rc:,%d \n",rc);
Thread_unlock_mutex(mqttclient_mutex);
FUNC_EXIT_RC(rc);
printf("DEBUG9:rc:,%d \n",rc);
return rc;
|
|
|
|
Re: MQTTClient PublishMessage Bug [message #1737879 is a reply to message #1737697] |
Wed, 13 July 2016 14:28  |
Eclipse User |
|
|
|
Yes I have message arrived callback and connection lost callback methods. But connection lost callback doesn't work without cases such as broker's turn off normally etc. So there is no callback about ethernet cable or network problems. I plugged off the cable any close moment before PublishMessage
|
|
|
Powered by
FUDForum. Page generated in 0.03350 seconds