mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-02 20:05:24 +08:00
Fix handling of socket write errors
PUBLISHED_FROM=7264edfb3b8e4e37f15f2993f479dfe0a9550b1d
This commit is contained in:
parent
459cd1b095
commit
68437de416
20
mongoose.c
20
mongoose.c
@ -2803,9 +2803,10 @@ static void mg_write_to_socket(struct mg_connection *nc) {
|
||||
DBG(("%p %d bytes -> %d (SSL)", nc, n, nc->sock));
|
||||
if (n <= 0) {
|
||||
int ssl_err = mg_ssl_err(nc, n);
|
||||
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
|
||||
return; /* Call us again */
|
||||
if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) {
|
||||
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
/* Successful SSL operation, clear off SSL wait flags */
|
||||
nc->flags &= ~(MG_F_WANT_READ | MG_F_WANT_WRITE);
|
||||
@ -2819,7 +2820,11 @@ static void mg_write_to_socket(struct mg_connection *nc) {
|
||||
{
|
||||
n = (int) MG_SEND_FUNC(nc->sock, io->buf, io->len, 0);
|
||||
DBG(("%p %d bytes -> %d", nc, n, nc->sock));
|
||||
if (n < 0 && !mg_is_error(n)) return;
|
||||
if (n < 0 && mg_is_error(n)) {
|
||||
/* Something went wrong, drop the connection. */
|
||||
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
@ -10607,22 +10612,21 @@ static void mg_write_to_socket(struct mg_connection *nc) {
|
||||
int n = 0;
|
||||
|
||||
if (nc->flags & MG_F_UDP) {
|
||||
int n = sl_SendTo(nc->sock, io->buf, io->len, 0, &nc->sa.sa,
|
||||
n = sl_SendTo(nc->sock, io->buf, io->len, 0, &nc->sa.sa,
|
||||
sizeof(nc->sa.sin));
|
||||
DBG(("%p %d %d %d %s:%hu", nc, nc->sock, n, errno,
|
||||
inet_ntoa(nc->sa.sin.sin_addr), ntohs(nc->sa.sin.sin_port)));
|
||||
if (n > 0) mbuf_remove(io, n);
|
||||
mg_if_sent_cb(nc, n);
|
||||
return;
|
||||
} else {
|
||||
n = (int) sl_Send(nc->sock, io->buf, io->len, 0);
|
||||
DBG(("%p %d bytes -> %d", nc, n, nc->sock));
|
||||
if (n < 0 && !mg_is_error(n)) return;
|
||||
}
|
||||
|
||||
if (n > 0) {
|
||||
mbuf_remove(io, n);
|
||||
mg_if_sent_cb(nc, n);
|
||||
} else if (n < 0 && mg_is_error(n)) {
|
||||
/* Something went wrong, drop the connection. */
|
||||
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user