Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform Service MQTT client - connection lost handling broken #65

Open
fishkeeper87 opened this issue Feb 5, 2021 · 0 comments
Open

Comments

@fishkeeper87
Copy link

Hello, I'm using the platform service for the sample mqtt client directory /apps/platformservices/mqttClient

I've been doing some testing with this client and noted that the logic included inside function ConnectionLostEventHandler never works as the return to the following is always NULL:

mqtt_Session* s = le_ref_Lookup(SessionRefMap, reportPtr);

I looked at how the event handler is factored for the MessageReceivedEventHandler and this implementation is working. I changed the functions as follows and the ConnectionLostEventHandler now processes successfully. I hope this fix can be included to save other people's time in diagnosing what is wrong. I've left my debug statements below.

static void ConnectionLostHandler
(
    void* contextPtr, ///< context parameter contains the session for which the connection was lost
    char* causePtr    ///< paho library doesn't currently populate this
)
{
    LE_DEBUG("ConnectionLostHandler with session 0x%p.",contextPtr);

    mqtt_Message* storedMsgPtr = le_mem_ForceAlloc(MessagePoolRef);
    LE_ASSERT(storedMsgPtr);
    memset(storedMsgPtr, 0, sizeof(*storedMsgPtr));

    storedMsgPtr->sessionRef = contextPtr;
    le_event_Report(ConnectionLostThreadEventId, &storedMsgPtr, sizeof(void*));
}

//--------------------------------------------------------------------------------------------------
/**
 * The event handler for the connection lost event that is generated by ConnectionLostHandler.
 * This function calls the handler supplied by the client.
 */
//--------------------------------------------------------------------------------------------------
static void ConnectionLostEventHandler
(
    void* reportPtr
)
{
    mqtt_Message* storedMsgPtr = *((mqtt_Message**)reportPtr);

    LE_DEBUG("Session lookup for session=%p", storedMsgPtr->sessionRef);
    mqtt_Session* s = le_ref_Lookup(SessionRefMap, storedMsgPtr->sessionRef);
    if (s == NULL)
    {
        LE_ERROR("Session with 0x%p not found.",&reportPtr);
        LE_KILL_CLIENT("Session doesn't exist");
        return;
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant