Open Yenya opened 10 months ago
It should definitely be possible to abstract I/O out, but I don't have the time to look into that. Is this something you'd be able to do? I wouldn't mind reviewing and maybe merging a good pull request. (Merging would of course depend on quality and backwards compatibility.)
@Juerd: Thanks for the reply. I will look at it, if I manage to find some free time :-).
Related: is it easy to add a method for returning the socket filehandle so that an existing loop can poll it for activity? The application would then call tick(0) when input is received. This is a pretty common idiom for networking libraries (libmosquitto even provides a function to do this for using MQTT from C). It's likely possible to poke around in the object structure and get the socket directly, but an official API would be more reliable.
Not very easy, since this module manages its own connections internally. There is no socket after object construction yet, and the socket may be replaced in between calls of tick(). One thing that comes to mind is to add a method to register callback functions to handle new socket creation; the supplied function would be used to add the new socket to the set of descriptors to select/poll. But I don't know how to actually recognise disconnection and trigger reconnection in that case.
I'm open to suggestions as long as they're compatible with the automatic reconnection paradigm.
I forgot it reconnects internally, so that simple approach wouldn't work. A callback is probably the best way to do it then, but I'd have to look at the implementation a little bit to figure out how it would work.
Hello,
thanks for this module, it works for me!
I wonder if Net::MQTT::Simple could be modified to work over a connection provided by an existing non-blocking event loop, preferably something like Mojo::IOLoop::Client, https://metacpan.org/pod/Mojo::IOLoop::Client .
Can this module do only message parsing and delegate I/O to some other entity?
Thanks,
-Yenya