mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-19 19:40:56 +00:00
Fill c->loc for outbound connections
This commit is contained in:
1 parent
d745c41d5b
commit
5baa4d969e
3 files changed
+22
-23
No files matched your search
+10
-11
@@ -7160,12 +7160,8 @@ static void iolog(struct mg_connection *c, char *buf, long n, bool r) {
|
|||||||
c->is_closing = 1; // Termination. Don't call mg_error(): #1529
|
c->is_closing = 1; // Termination. Don't call mg_error(): #1529
|
||||||
} else if (n > 0) {
|
} else if (n > 0) {
|
||||||
if (c->is_hexdumping) {
|
if (c->is_hexdumping) {
|
||||||
union usa usa;
|
|
||||||
socklen_t slen = sizeof(usa.sin);
|
|
||||||
if (getsockname(FD(c), &usa.sa, &slen) < 0) (void) 0; // Ignore result
|
|
||||||
MG_INFO(("\n-- %lu %M %s %M %ld", c->id, mg_print_ip_port, &c->loc,
|
MG_INFO(("\n-- %lu %M %s %M %ld", c->id, mg_print_ip_port, &c->loc,
|
||||||
r ? "<-" : "->", mg_print_ip_port, &c->rem, n));
|
r ? "<-" : "->", mg_print_ip_port, &c->rem, n));
|
||||||
|
|
||||||
mg_hexdump(buf, (size_t) n);
|
mg_hexdump(buf, (size_t) n);
|
||||||
}
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
@@ -7393,6 +7389,7 @@ static void connect_conn(struct mg_connection *c) {
|
|||||||
// Use getpeername() to test whether we have connected
|
// Use getpeername() to test whether we have connected
|
||||||
if (getpeername(FD(c), &usa.sa, &n) == 0) {
|
if (getpeername(FD(c), &usa.sa, &n) == 0) {
|
||||||
c->is_connecting = 0;
|
c->is_connecting = 0;
|
||||||
|
setlocaddr(FD(c), &c->loc);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL);
|
mg_call(c, MG_EV_CONNECT, NULL);
|
||||||
MG_EPOLL_MOD(c, 0);
|
MG_EPOLL_MOD(c, 0);
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||||
@@ -7433,6 +7430,7 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
if ((rc = bind(c->fd, &usa.sa, slen)) != 0)
|
if ((rc = bind(c->fd, &usa.sa, slen)) != 0)
|
||||||
MG_ERROR(("bind: %d", MG_SOCK_ERR(rc)));
|
MG_ERROR(("bind: %d", MG_SOCK_ERR(rc)));
|
||||||
#endif
|
#endif
|
||||||
|
setlocaddr(FD(c), &c->loc);
|
||||||
mg_call(c, MG_EV_RESOLVE, NULL);
|
mg_call(c, MG_EV_RESOLVE, NULL);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL);
|
mg_call(c, MG_EV_CONNECT, NULL);
|
||||||
} else {
|
} else {
|
||||||
@@ -7444,8 +7442,9 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
mg_call(c, MG_EV_RESOLVE, NULL);
|
mg_call(c, MG_EV_RESOLVE, NULL);
|
||||||
rc = connect(FD(c), &usa.sa, slen); // Attempt to connect
|
rc = connect(FD(c), &usa.sa, slen); // Attempt to connect
|
||||||
if (rc == 0) { // Success
|
if (rc == 0) { // Success
|
||||||
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
|
setlocaddr(FD(c), &c->loc);
|
||||||
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
|
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
|
||||||
|
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
|
||||||
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
|
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
|
||||||
c->is_connecting = 1;
|
c->is_connecting = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -7757,11 +7756,11 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
|||||||
long n = 0;
|
long n = 0;
|
||||||
mg_call(c, MG_EV_READ, &n);
|
mg_call(c, MG_EV_READ, &n);
|
||||||
}
|
}
|
||||||
MG_VERBOSE(("%lu %c%c %c%c%c%c%c %lu %lu", c->id, c->is_readable ? 'r' : '-',
|
MG_VERBOSE(("%lu %c%c %c%c%c%c%c %lu %lu", c->id,
|
||||||
c->is_writable ? 'w' : '-', c->is_tls ? 'T' : 't',
|
c->is_readable ? 'r' : '-', c->is_writable ? 'w' : '-',
|
||||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
c->is_tls ? 'T' : 't', c->is_connecting ? 'C' : 'c',
|
||||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
|
c->is_tls_hs ? 'H' : 'h', c->is_resolving ? 'R' : 'r',
|
||||||
mg_tls_pending(c), c->rtls.len));
|
c->is_closing ? 'C' : 'c', mg_tls_pending(c), c->rtls.len));
|
||||||
if (c->is_resolving || c->is_closing) {
|
if (c->is_resolving || c->is_closing) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else if (c->is_listening && c->is_udp == 0) {
|
} else if (c->is_listening && c->is_udp == 0) {
|
||||||
|
|||||||
+10
-11
@@ -98,12 +98,8 @@ static void iolog(struct mg_connection *c, char *buf, long n, bool r) {
|
|||||||
c->is_closing = 1; // Termination. Don't call mg_error(): #1529
|
c->is_closing = 1; // Termination. Don't call mg_error(): #1529
|
||||||
} else if (n > 0) {
|
} else if (n > 0) {
|
||||||
if (c->is_hexdumping) {
|
if (c->is_hexdumping) {
|
||||||
union usa usa;
|
|
||||||
socklen_t slen = sizeof(usa.sin);
|
|
||||||
if (getsockname(FD(c), &usa.sa, &slen) < 0) (void) 0; // Ignore result
|
|
||||||
MG_INFO(("\n-- %lu %M %s %M %ld", c->id, mg_print_ip_port, &c->loc,
|
MG_INFO(("\n-- %lu %M %s %M %ld", c->id, mg_print_ip_port, &c->loc,
|
||||||
r ? "<-" : "->", mg_print_ip_port, &c->rem, n));
|
r ? "<-" : "->", mg_print_ip_port, &c->rem, n));
|
||||||
|
|
||||||
mg_hexdump(buf, (size_t) n);
|
mg_hexdump(buf, (size_t) n);
|
||||||
}
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
@@ -331,6 +327,7 @@ static void connect_conn(struct mg_connection *c) {
|
|||||||
// Use getpeername() to test whether we have connected
|
// Use getpeername() to test whether we have connected
|
||||||
if (getpeername(FD(c), &usa.sa, &n) == 0) {
|
if (getpeername(FD(c), &usa.sa, &n) == 0) {
|
||||||
c->is_connecting = 0;
|
c->is_connecting = 0;
|
||||||
|
setlocaddr(FD(c), &c->loc);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL);
|
mg_call(c, MG_EV_CONNECT, NULL);
|
||||||
MG_EPOLL_MOD(c, 0);
|
MG_EPOLL_MOD(c, 0);
|
||||||
if (c->is_tls_hs) mg_tls_handshake(c);
|
if (c->is_tls_hs) mg_tls_handshake(c);
|
||||||
@@ -371,6 +368,7 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
if ((rc = bind(c->fd, &usa.sa, slen)) != 0)
|
if ((rc = bind(c->fd, &usa.sa, slen)) != 0)
|
||||||
MG_ERROR(("bind: %d", MG_SOCK_ERR(rc)));
|
MG_ERROR(("bind: %d", MG_SOCK_ERR(rc)));
|
||||||
#endif
|
#endif
|
||||||
|
setlocaddr(FD(c), &c->loc);
|
||||||
mg_call(c, MG_EV_RESOLVE, NULL);
|
mg_call(c, MG_EV_RESOLVE, NULL);
|
||||||
mg_call(c, MG_EV_CONNECT, NULL);
|
mg_call(c, MG_EV_CONNECT, NULL);
|
||||||
} else {
|
} else {
|
||||||
@@ -382,8 +380,9 @@ void mg_connect_resolved(struct mg_connection *c) {
|
|||||||
mg_call(c, MG_EV_RESOLVE, NULL);
|
mg_call(c, MG_EV_RESOLVE, NULL);
|
||||||
rc = connect(FD(c), &usa.sa, slen); // Attempt to connect
|
rc = connect(FD(c), &usa.sa, slen); // Attempt to connect
|
||||||
if (rc == 0) { // Success
|
if (rc == 0) { // Success
|
||||||
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
|
setlocaddr(FD(c), &c->loc);
|
||||||
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
|
mg_call(c, MG_EV_CONNECT, NULL); // Send MG_EV_CONNECT to the user
|
||||||
|
} else if (MG_SOCK_PENDING(rc)) { // Need to wait for TCP handshake
|
||||||
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
|
MG_DEBUG(("%lu %ld -> %M pend", c->id, c->fd, mg_print_ip_port, &c->rem));
|
||||||
c->is_connecting = 1;
|
c->is_connecting = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -695,11 +694,11 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
|
|||||||
long n = 0;
|
long n = 0;
|
||||||
mg_call(c, MG_EV_READ, &n);
|
mg_call(c, MG_EV_READ, &n);
|
||||||
}
|
}
|
||||||
MG_VERBOSE(("%lu %c%c %c%c%c%c%c %lu %lu", c->id, c->is_readable ? 'r' : '-',
|
MG_VERBOSE(("%lu %c%c %c%c%c%c%c %lu %lu", c->id,
|
||||||
c->is_writable ? 'w' : '-', c->is_tls ? 'T' : 't',
|
c->is_readable ? 'r' : '-', c->is_writable ? 'w' : '-',
|
||||||
c->is_connecting ? 'C' : 'c', c->is_tls_hs ? 'H' : 'h',
|
c->is_tls ? 'T' : 't', c->is_connecting ? 'C' : 'c',
|
||||||
c->is_resolving ? 'R' : 'r', c->is_closing ? 'C' : 'c',
|
c->is_tls_hs ? 'H' : 'h', c->is_resolving ? 'R' : 'r',
|
||||||
mg_tls_pending(c), c->rtls.len));
|
c->is_closing ? 'C' : 'c', mg_tls_pending(c), c->rtls.len));
|
||||||
if (c->is_resolving || c->is_closing) {
|
if (c->is_resolving || c->is_closing) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
} else if (c->is_listening && c->is_udp == 0) {
|
} else if (c->is_listening && c->is_udp == 0) {
|
||||||
|
|||||||
+2
-1
@@ -1249,6 +1249,7 @@ static void test_http_client(void) {
|
|||||||
MG_INFO(("%d", ok));
|
MG_INFO(("%d", ok));
|
||||||
ASSERT(ok == 301);
|
ASSERT(ok == 301);
|
||||||
c->is_closing = 1;
|
c->is_closing = 1;
|
||||||
|
ASSERT((c->loc.ip[0] != 0)); // Make sure that c->loc address is populated
|
||||||
mg_mgr_poll(&mgr, 0);
|
mg_mgr_poll(&mgr, 0);
|
||||||
ok = 0;
|
ok = 0;
|
||||||
#if MG_TLS
|
#if MG_TLS
|
||||||
@@ -1402,7 +1403,7 @@ static void test_http_pipeline(void) {
|
|||||||
for (i = 0; i < 20; i++) mg_mgr_poll(&mgr, 1);
|
for (i = 0; i < 20; i++) mg_mgr_poll(&mgr, 1);
|
||||||
ASSERT(ok == 1);
|
ASSERT(ok == 1);
|
||||||
ASSERT(ok2 == 1);
|
ASSERT(ok2 == 1);
|
||||||
//MG_INFO(("-----> [%d] [%d]", ok, ok2));
|
// MG_INFO(("-----> [%d] [%d]", ok, ok2));
|
||||||
mg_mgr_free(&mgr);
|
mg_mgr_free(&mgr);
|
||||||
ASSERT(mgr.conns == NULL);
|
ASSERT(mgr.conns == NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user