is there any option that can specifiy a timeout when using msg_connection? #1592
-
I want to control the connect waiting time, is there any api that can config this ? thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As far as I can see, that would depend on your TCP/IP stack implementation. You can always retry if time is not long enough |
Beta Was this translation helpful? Give feedback.
-
Connect timeout should be done manually. The http-client example has that implemented - https://github.com/cesanta/mongoose/blob/master/examples/http-client/main.c We probably should move that into a separate example and tutorial. |
Beta Was this translation helpful? Give feedback.
Connect timeout should be done manually.
The idea is: when a connection is created (MG_EV_OPEN event), store current timestamp (mg_millis()) into a c->label buffer. Then, on each MG_EV_POLL, check the current timestamp and c->is_connecting / c->is_resolving flags. Close if takes too long.
The http-client example has that implemented - https://github.com/cesanta/mongoose/blob/master/examples/http-client/main.c
We probably should move that into a separate example and tutorial.