Commit b4dbc825 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Marko Mikulicic

Minor fixes to Mongoose

    PUBLISHED_FROM=8a8692e5cfaab63723fc9e241a50e8f229a26438
parent 4a0cc822
...@@ -2123,7 +2123,9 @@ void mg_if_timer(struct mg_connection *c, double now) { ...@@ -2123,7 +2123,9 @@ void mg_if_timer(struct mg_connection *c, double now) {
} }
void mg_if_poll(struct mg_connection *nc, time_t now) { void mg_if_poll(struct mg_connection *nc, time_t now) {
mg_call(nc, NULL, MG_EV_POLL, &now); if (nc->ssl == NULL || (nc->flags & MG_F_SSL_HANDSHAKE_DONE)) {
mg_call(nc, NULL, MG_EV_POLL, &now);
}
} }
static void mg_destroy_conn(struct mg_connection *conn) { static void mg_destroy_conn(struct mg_connection *conn) {
...@@ -3236,6 +3238,7 @@ static void mg_write_to_socket(struct mg_connection *nc) { ...@@ -3236,6 +3238,7 @@ static void mg_write_to_socket(struct mg_connection *nc) {
if (nc->ssl != NULL) { if (nc->ssl != NULL) {
if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) { if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
n = SSL_write(nc->ssl, io->buf, io->len); n = SSL_write(nc->ssl, io->buf, io->len);
DBG(("%p %d bytes -> %d (SSL)", nc, n, nc->sock));
if (n <= 0) { if (n <= 0) {
int ssl_err = mg_ssl_err(nc, n); int ssl_err = mg_ssl_err(nc, n);
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) { if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
...@@ -3253,10 +3256,9 @@ static void mg_write_to_socket(struct mg_connection *nc) { ...@@ -3253,10 +3256,9 @@ static void mg_write_to_socket(struct mg_connection *nc) {
#endif #endif
{ {
n = (int) MG_SEND_FUNC(nc->sock, io->buf, io->len, 0); n = (int) MG_SEND_FUNC(nc->sock, io->buf, io->len, 0);
DBG(("%p %d bytes -> %d", nc, n, nc->sock));
} }
DBG(("%p %d bytes -> %d", nc, n, nc->sock));
if (n > 0) { if (n > 0) {
mbuf_remove(io, n); mbuf_remove(io, n);
} }
...@@ -3361,7 +3363,7 @@ static int mg_ssl_err(struct mg_connection *conn, int res) { ...@@ -3361,7 +3363,7 @@ static int mg_ssl_err(struct mg_connection *conn, int res) {
} }
static void mg_ssl_begin(struct mg_connection *nc) { static void mg_ssl_begin(struct mg_connection *nc) {
int server_side = nc->listener != NULL; int server_side = (nc->listener != NULL);
int res = server_side ? SSL_accept(nc->ssl) : SSL_connect(nc->ssl); int res = server_side ? SSL_accept(nc->ssl) : SSL_connect(nc->ssl);
DBG(("%p %d res %d %d", nc, server_side, res, errno)); DBG(("%p %d res %d %d", nc, server_side, res, errno));
...@@ -3372,8 +3374,7 @@ static void mg_ssl_begin(struct mg_connection *nc) { ...@@ -3372,8 +3374,7 @@ static void mg_ssl_begin(struct mg_connection *nc) {
if (server_side) { if (server_side) {
union socket_address sa; union socket_address sa;
socklen_t sa_len = sizeof(sa); socklen_t sa_len = sizeof(sa);
/* In case port was set to 0, get the real port number */ (void) getpeername(nc->sock, &sa.sa, &sa_len);
(void) getsockname(nc->sock, &sa.sa, &sa_len);
mg_if_accept_tcp_cb(nc, &sa, sa_len); mg_if_accept_tcp_cb(nc, &sa, sa_len);
} else { } else {
mg_if_connect_cb(nc, 0); mg_if_connect_cb(nc, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment