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

Adds custom pointer for mqtt_client, option to pass client to pal #21

Closed
wants to merge 1 commit into from

Conversation

lukeMlng
Copy link

@lukeMlng lukeMlng commented Aug 7, 2018

Hey I made this two optional additions:

  • A custom pointer to store additional info and states for each client. mqtt_client->custom
  • Option to pass the client pointer to the PAL. In combination with the custom pointer this can be used to forward the send and recv calls to an existing network implementation.
    Can be turned on with MQTT_USE_CUSTOM_PAL_PTR

Thank you for the great library!

…ent, add option to make the client struct available for the pal
@LiamBindle
Copy link
Owner

Hi Luke, thanks for the pull request!

Great idea! I can see how this would be useful. I will review your changes this weekend and merge your request.

Thanks for your contribution,

Liam

@LiamBindle
Copy link
Owner

Hi Luke,

I just finished reviewing your pull request.

Regarding the custom pointer, the mqtt_client->reconnect_state pointer can be used to associate a custom data-structure with an mqtt_client.

Regarding passing the mqtt_client to your PAL's send/recv functions, this can be accomplished by implementing a custom socket handle.


Example of custom socket handle

Your custom socket handle could look something like this

struct my_custom_socket_handle {
    void* client;
    int socketfd;
    const char* client_name;
};

Line 64-70 of mqtt_pal.h typedefs mqtt_pal_socket handle. Therefore, you would put something like this

typedef my_custom_socket_handle* mqtt_pal_socket_handle;

Now, MQTT-C will pass a pointer to my_custom_socket_handle to your PAL's send/recv functions.


I am going to close this pull request because I don't believe it adds any additional functionality. Please feel free to re-open the request if I have misunderstood something.

Thanks again for the pull request, I really do appreciate it.

Regards,

Liam

@LiamBindle
Copy link
Owner

I opened issue #22 because it would be nice if we could use a custom socket handle without modifying MQTT-C's source code.

@lukeMlng
Copy link
Author

Hi Liam,
this is exactly what I was trying to accomplish.
That's way more elegant than my approach.
Missed that part with mqtt_client->reconnect_state.
Thanks a lot for your efforts and the example!

Regards,
Luke

@LiamBindle
Copy link
Owner

No problem, glad I could help!

Liam

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

Successfully merging this pull request may close these issues.

None yet

2 participants