Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] paho-dev Digest, Vol54 , Issue 12

  Hi paho team,
  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

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;
}

2016-06-29 10:18 GMT+03:00 Rutkay Bıyık <rutkay.biyik@xxxxxxxxxxx>:
  Sorry for wrong mail with wrong content,
  I'm re-mailing the last mail with better combination :

  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
  
  Thanks,


Back to the top