Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » MQTTClient PublishMessage Bug(The code stuck on PublishMessage Method)
icon4.gif  MQTTClient PublishMessage Bug [message #1737697] Tue, 12 July 2016 06:10 Go to next message
Azmi rutkay BIYIK is currently offline Azmi rutkay BIYIKFriend
Messages: 2
Registered: July 2016
Junior Member
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 #1737821 is a reply to message #1737697] Wed, 13 July 2016 09:33 Go to previous messageGo to next message
Ian Craggs is currently offline Ian CraggsFriend
Messages: 68
Registered: March 2013
Member
Hello.

Are you setting callbacks, such as messageArrived? Doing so starts a background thread and may change the behaviour.

At what point are you removing the network cable?





Re: MQTTClient PublishMessage Bug [message #1737879 is a reply to message #1737697] Wed, 13 July 2016 18:28 Go to previous message
Azmi rutkay BIYIK is currently offline Azmi rutkay BIYIKFriend
Messages: 2
Registered: July 2016
Junior Member
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
Previous Topic:embedded c client: keepalive failure detection
Next Topic:connectWithResult(options) infinite wait
Goto Forum:
  


Current Time: Sat Nov 17 23:59:23 GMT 2018

Powered by FUDForum. Page generated in 0.05431 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top