mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-27 15:01:03 +08:00
Factor mg_connect() to net.c
This commit is contained in:
parent
3a249183f8
commit
a287fd97e4
37
mongoose.c
37
mongoose.c
@ -2747,6 +2747,24 @@ struct mg_connection *mg_alloc_conn(struct mg_mgr *mgr, bool clnt, void *fd) {
|
||||
}
|
||||
return c;
|
||||
}
|
||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
||||
mg_event_handler_t fn, void *fn_data) {
|
||||
struct mg_connection *c = NULL;
|
||||
if (url == NULL || url[0] == '\0') {
|
||||
MG_ERROR(("null url"));
|
||||
} else if ((c = mg_alloc_conn(mgr, true, NULL)) == NULL) {
|
||||
MG_ERROR(("OOM"));
|
||||
} else {
|
||||
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
|
||||
c->is_udp = (strncmp(url, "udp:", 4) == 0);
|
||||
c->fn = fn;
|
||||
c->fn_data = fn_data;
|
||||
MG_DEBUG(("%lu -> %s", c->id, url));
|
||||
mg_call(c, MG_EV_OPEN, NULL);
|
||||
mg_resolve(c, url);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void mg_mgr_free(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c;
|
||||
@ -3471,25 +3489,6 @@ void mg_connect_resolved(struct mg_connection *c) {
|
||||
}
|
||||
}
|
||||
|
||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
||||
mg_event_handler_t fn, void *fn_data) {
|
||||
struct mg_connection *c = NULL;
|
||||
if (url == NULL || url[0] == '\0') {
|
||||
MG_ERROR(("null url"));
|
||||
} else if ((c = mg_alloc_conn(mgr, true, S2PTR(INVALID_SOCKET))) == NULL) {
|
||||
MG_ERROR(("OOM"));
|
||||
} else {
|
||||
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
|
||||
c->is_udp = (strncmp(url, "udp:", 4) == 0);
|
||||
c->fn = fn;
|
||||
c->fn_data = fn_data;
|
||||
MG_DEBUG(("%lu -> %s", c->id, url));
|
||||
mg_call(c, MG_EV_OPEN, NULL);
|
||||
mg_resolve(c, url);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
struct mg_connection *c = NULL;
|
||||
union usa usa;
|
||||
|
18
src/net.c
18
src/net.c
@ -145,6 +145,24 @@ struct mg_connection *mg_alloc_conn(struct mg_mgr *mgr, bool clnt, void *fd) {
|
||||
}
|
||||
return c;
|
||||
}
|
||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
||||
mg_event_handler_t fn, void *fn_data) {
|
||||
struct mg_connection *c = NULL;
|
||||
if (url == NULL || url[0] == '\0') {
|
||||
MG_ERROR(("null url"));
|
||||
} else if ((c = mg_alloc_conn(mgr, true, NULL)) == NULL) {
|
||||
MG_ERROR(("OOM"));
|
||||
} else {
|
||||
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
|
||||
c->is_udp = (strncmp(url, "udp:", 4) == 0);
|
||||
c->fn = fn;
|
||||
c->fn_data = fn_data;
|
||||
MG_DEBUG(("%lu -> %s", c->id, url));
|
||||
mg_call(c, MG_EV_OPEN, NULL);
|
||||
mg_resolve(c, url);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void mg_mgr_free(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c;
|
||||
|
19
src/sock.c
19
src/sock.c
@ -360,25 +360,6 @@ void mg_connect_resolved(struct mg_connection *c) {
|
||||
}
|
||||
}
|
||||
|
||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *url,
|
||||
mg_event_handler_t fn, void *fn_data) {
|
||||
struct mg_connection *c = NULL;
|
||||
if (url == NULL || url[0] == '\0') {
|
||||
MG_ERROR(("null url"));
|
||||
} else if ((c = mg_alloc_conn(mgr, true, S2PTR(INVALID_SOCKET))) == NULL) {
|
||||
MG_ERROR(("OOM"));
|
||||
} else {
|
||||
LIST_ADD_HEAD(struct mg_connection, &mgr->conns, c);
|
||||
c->is_udp = (strncmp(url, "udp:", 4) == 0);
|
||||
c->fn = fn;
|
||||
c->fn_data = fn_data;
|
||||
MG_DEBUG(("%lu -> %s", c->id, url));
|
||||
mg_call(c, MG_EV_OPEN, NULL);
|
||||
mg_resolve(c, url);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static void accept_conn(struct mg_mgr *mgr, struct mg_connection *lsn) {
|
||||
struct mg_connection *c = NULL;
|
||||
union usa usa;
|
||||
|
Loading…
x
Reference in New Issue
Block a user