MyQttMsg * myqtt_conn_get_next ( MyQttConn conn,
long  timeout 

Allows to implement a simple synchronous wait for the next message (PUBLISH) received on the provided connection limiting that wait to the provided timeout (in milliseconds).

connThe connection where the wait operation for the next (MYQTT_PUBLISH) message will take place.
timeoutThe timeout to limit the operation. If it is set to 0 it will wait for ever. This value is provided in milliseconds (1000 ms = 1sec)
A reference to the message received or NULL if it fails or timeout was reached. The function also returns NULL when the connection is closed during the wait operation. In the case the function returns a MyQttMsg reference you must call to myqtt_msg_unref after finishing with it.

NOTE: the function will replace the MyQttOnMsgReceived handler that was previously configured by myqtt_conn_set_on_msg but it will be restored once the function finishes.

Notes about using this function to receive a particular message

This function is useful for simple generic blocking wait operation. However, it is not recommended when expected to receive a particular message because a particular myqtt_conn_pub done before. Here is why:

If you myqtt_conn_pub to the server, and then call to this function (expecting to receive a reply), you may lose it because at the time you are about to call to myqtt_conn_get_next, the thread planner may give priority to notify incoming message and, because you didn't set any on message handler, that message is lost and hence, calling to myqtt_conn_get_next will not return it.

So, the recommended solution to work out this situation is to call first to setup a MyQttOnMsgReceived to ensure that reception mechanism is already in place when you issue the PUB (myqtt_conn_pub) message.

Here is a short example:

1 // create queue
2 queue = myqtt_async_queue_new ();
3 myqtt_conn_set_on_msg (conn, test_03_on_message, queue);
5 // call to get client identifier
6 if (! myqtt_conn_pub (conn, "myqtt/admin/get-tls-status", "", 0, MYQTT_QOS_0, axl_false, 0)) {
7  printf ("ERROR: unable to publish message to get client identifier..\n");
8  return axl_false;
9 }
11 // push a message to ask for client id identifier
12 msg = myqtt_async_queue_timedpop (queue, 10000000);
13 myqtt_async_queue_unref (queue);

References msg, myqtt_async_queue_new(), myqtt_async_queue_pop(), myqtt_async_queue_timedpop(), myqtt_async_queue_unref(), myqtt_conn_is_ok(), myqtt_conn_remove_on_close(), myqtt_conn_set_on_close(), myqtt_mutex_lock(), and myqtt_mutex_unlock().