@@ -2589,9 +2589,7 @@ void mg_hello(const char *url) {
25892589
25902590struct mg_connection *mg_http_connect(struct mg_mgr *mgr, const char *url,
25912591 mg_event_handler_t fn, void *fn_data) {
2592- struct mg_connection *c = mg_connect(mgr, url, fn, fn_data);
2593- if (c != NULL) c->pfn = http_cb;
2594- return c;
2592+ return mg_connect_svc(mgr, url, fn, fn_data, http_cb, NULL);
25952593}
25962594
25972595struct mg_connection *mg_http_listen(struct mg_mgr *mgr, const char *url,
@@ -3858,12 +3856,11 @@ void mg_mqtt_disconnect(struct mg_connection *c,
38583856struct mg_connection *mg_mqtt_connect(struct mg_mgr *mgr, const char *url,
38593857 const struct mg_mqtt_opts *opts,
38603858 mg_event_handler_t fn, void *fn_data) {
3861- struct mg_connection *c = mg_connect (mgr, url, fn, fn_data);
3859+ struct mg_connection *c = mg_connect_svc (mgr, url, fn, fn_data, mqtt_cb, NULL );
38623860 if (c != NULL) {
38633861 struct mg_mqtt_opts empty;
38643862 memset(&empty, 0, sizeof(empty));
38653863 mg_mqtt_login(c, opts == NULL ? &empty : opts);
3866- c->pfn = mqtt_cb;
38673864 }
38683865 return c;
38693866}
@@ -4036,8 +4033,8 @@ void mg_close_conn(struct mg_connection *c) {
40364033 mg_free(c);
40374034}
40384035
4039- struct mg_connection *mg_connect (struct mg_mgr *mgr, const char *url,
4040- mg_event_handler_t fn, void *fn_data) {
4036+ struct mg_connection *mg_connect_svc (struct mg_mgr *mgr, const char *url,
4037+ mg_event_handler_t fn, void *fn_data, mg_event_handler_t pfn, void *pfn_data ) {
40414038 struct mg_connection *c = NULL;
40424039 if (url == NULL || url[0] == '\0') {
40434040 MG_ERROR(("null url"));
@@ -4051,13 +4048,20 @@ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
40514048 c->is_client = true;
40524049 c->fn_data = fn_data;
40534050 c->is_tls = (mg_url_is_ssl(url) != 0);
4051+ c->pfn = pfn;
4052+ c->pfn_data = pfn_data;
40544053 mg_call(c, MG_EV_OPEN, (void *) url);
40554054 MG_DEBUG(("%lu %ld %s", c->id, c->fd, url));
40564055 mg_resolve(c, url);
40574056 }
40584057 return c;
40594058}
40604059
4060+ struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
4061+ mg_event_handler_t fn, void *fn_data) {
4062+ return mg_connect_svc(mgr, url, fn, fn_data, NULL, NULL);
4063+ }
4064+
40614065struct mg_connection *mg_listen(struct mg_mgr *mgr, const char *url,
40624066 mg_event_handler_t fn, void *fn_data) {
40634067 struct mg_connection *c = NULL;
@@ -8596,8 +8600,10 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
85968600static void sntp_cb(struct mg_connection *c, int ev, void *ev_data) {
85978601 uint64_t *expiration_time = (uint64_t *) c->data;
85988602 if (ev == MG_EV_OPEN) {
8603+ MG_INFO(("%lu PFN OPEN", c->id));
85998604 *expiration_time = mg_millis() + 3000; // Store expiration time in 3s
86008605 } else if (ev == MG_EV_CONNECT) {
8606+ MG_INFO(("%lu PFN CONNECT, sending request", c->id));
86018607 mg_sntp_request(c);
86028608 } else if (ev == MG_EV_READ) {
86038609 int64_t milliseconds = mg_sntp_parse(c->recv.buf, c->recv.len);
@@ -8631,14 +8637,9 @@ void mg_sntp_request(struct mg_connection *c) {
86318637}
86328638
86338639struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url,
8634- mg_event_handler_t fn, void *fnd) {
8635- struct mg_connection *c = NULL;
8640+ mg_event_handler_t fn, void *fn_data) {
86368641 if (url == NULL) url = "udp://time.google.com:123";
8637- if ((c = mg_connect(mgr, url, fn, fnd)) != NULL) {
8638- c->pfn = sntp_cb;
8639- sntp_cb(c, MG_EV_OPEN, (void *) url);
8640- }
8641- return c;
8642+ return mg_connect_svc(mgr, url, fn, fn_data, sntp_cb, NULL);
86428643}
86438644
86448645#ifdef MG_ENABLE_LINES
0 commit comments