-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add timeout arg to mosquitto_connect() function #3051
Comments
timeout should be addedd for all mosquitto connect funtion in the library |
I also have to fix my application timeout issue since my fool user configed host ip to a Windows PC with firewall :P @legale so you using And did you have multiple MQTT connection in the same select or epoll ? I tried to use I tried to modify I think if Now I decided to use a thread to do connect and change control to my event loop when it's connect return success. that's my experiense. |
This function allows me to use an arbitrary timeout for establishing a connection. When connection issues generate feedback to the Mosquitto client (e.g., rejected TCP packets), there are no problems, and the mosquitto_connect() function quickly returns a result. However, in situations where there is no feedback to the client (e.g., packets are dropped or disappear for other reasons), mosquitto_connect() can attempt an unsuccessful connection for several minutes.
To avoid modifying the libmosquitto library code, this external function works in conjunction with mosquitto_connect_async() and mosquitto_socket().
After calling the connect function, my function waits for a specified timeout period for the connection to be established. When this happens, the function returns 0. As a result, I achieve functionality that could be directly implemented in the library through a modified mosquitto_connect() function.
If we add an additional timeout argument:
int mosquitto_connect(struct mosquitto *mosq, const char *host, int port, int keepalive, int timeout)
We could implement the logic similar to the one used in my function inside this modified function.
What do you think about this?
The text was updated successfully, but these errors were encountered: