diff --git a/mongoose.c b/mongoose.c index 9f16cc9f..2c32aa01 100644 --- a/mongoose.c +++ b/mongoose.c @@ -8060,7 +8060,7 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) { } MG_VERBOSE(("%lu %ld %d", c->id, n, MG_SOCK_ERR(n))); if (MG_SOCK_PENDING(n)) return MG_IO_WAIT; - if (MG_SOCK_RESET(n)) return MG_IO_RESET; + if (MG_SOCK_RESET(n)) return MG_IO_RESET; // MbedTLS, see #1507 if (n <= 0) return MG_IO_ERR; return n; } @@ -8182,7 +8182,7 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) { } MG_VERBOSE(("%lu %ld %d", c->id, n, MG_SOCK_ERR(n))); if (MG_SOCK_PENDING(n)) return MG_IO_WAIT; - if (MG_SOCK_RESET(n)) return MG_IO_RESET; + if (MG_SOCK_RESET(n)) return MG_IO_RESET; // MbedTLS, see #1507 if (n <= 0) return MG_IO_ERR; return n; } @@ -8219,7 +8219,7 @@ static void read_conn(struct mg_connection *c) { } // there can still be > 16K from last iteration, always mg_tls_recv() m = c->is_tls_hs ? (long) MG_IO_WAIT : mg_tls_recv(c, buf, len); - if (n == MG_IO_ERR) { + if (n == MG_IO_ERR || n == MG_IO_RESET) { // Windows, see #3031 if (c->rtls.len == 0 || m < 0) { // Close only when we have fully drained both rtls and TLS buffers c->is_closing = 1; // or there's nothing we can do about it. diff --git a/mongoose.h b/mongoose.h index 5f06db22..0d0c6a4d 100644 --- a/mongoose.h +++ b/mongoose.h @@ -3267,6 +3267,41 @@ struct mg_tcpip_driver_tms570_data { +#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC7) && MG_ENABLE_DRIVER_XMC7 + +struct mg_tcpip_driver_xmc7_data { + int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5 + uint8_t phy_addr; +}; + +#ifndef MG_TCPIP_PHY_ADDR +#define MG_TCPIP_PHY_ADDR 0 +#endif + +#ifndef MG_DRIVER_MDC_CR +#define MG_DRIVER_MDC_CR 3 +#endif + +#define MG_TCPIP_DRIVER_INIT(mgr) \ + do { \ + static struct mg_tcpip_driver_xmc7_data driver_data_; \ + static struct mg_tcpip_if mif_; \ + driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \ + driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \ + mif_.ip = MG_TCPIP_IP; \ + mif_.mask = MG_TCPIP_MASK; \ + mif_.gw = MG_TCPIP_GW; \ + mif_.driver = &mg_tcpip_driver_xmc7; \ + mif_.driver_data = &driver_data_; \ + MG_SET_MAC_ADDRESS(mif_.mac); \ + mg_tcpip_init(mgr, &mif_); \ + MG_INFO(("Driver: xmc7, MAC: %M", mg_print_mac, mif_.mac)); \ + } while (0) + +#endif + + + #if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC) && MG_ENABLE_DRIVER_XMC struct mg_tcpip_driver_xmc_data { @@ -3313,41 +3348,6 @@ struct mg_tcpip_driver_xmc_data { #endif - -#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC7) && MG_ENABLE_DRIVER_XMC7 - -struct mg_tcpip_driver_xmc7_data { - int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5 - uint8_t phy_addr; -}; - -#ifndef MG_TCPIP_PHY_ADDR -#define MG_TCPIP_PHY_ADDR 0 -#endif - -#ifndef MG_DRIVER_MDC_CR -#define MG_DRIVER_MDC_CR 3 -#endif - -#define MG_TCPIP_DRIVER_INIT(mgr) \ - do { \ - static struct mg_tcpip_driver_xmc7_data driver_data_; \ - static struct mg_tcpip_if mif_; \ - driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \ - driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \ - mif_.ip = MG_TCPIP_IP; \ - mif_.mask = MG_TCPIP_MASK; \ - mif_.gw = MG_TCPIP_GW; \ - mif_.driver = &mg_tcpip_driver_xmc7; \ - mif_.driver_data = &driver_data_; \ - MG_SET_MAC_ADDRESS(mif_.mac); \ - mg_tcpip_init(mgr, &mif_); \ - MG_INFO(("Driver: xmc7, MAC: %M", mg_print_mac, mif_.mac)); \ - } while (0) - -#endif - - #ifdef __cplusplus } #endif diff --git a/src/sock.c b/src/sock.c index c21f446c..9e991663 100644 --- a/src/sock.c +++ b/src/sock.c @@ -128,7 +128,7 @@ long mg_io_send(struct mg_connection *c, const void *buf, size_t len) { } MG_VERBOSE(("%lu %ld %d", c->id, n, MG_SOCK_ERR(n))); if (MG_SOCK_PENDING(n)) return MG_IO_WAIT; - if (MG_SOCK_RESET(n)) return MG_IO_RESET; + if (MG_SOCK_RESET(n)) return MG_IO_RESET; // MbedTLS, see #1507 if (n <= 0) return MG_IO_ERR; return n; } @@ -250,7 +250,7 @@ static long recv_raw(struct mg_connection *c, void *buf, size_t len) { } MG_VERBOSE(("%lu %ld %d", c->id, n, MG_SOCK_ERR(n))); if (MG_SOCK_PENDING(n)) return MG_IO_WAIT; - if (MG_SOCK_RESET(n)) return MG_IO_RESET; + if (MG_SOCK_RESET(n)) return MG_IO_RESET; // MbedTLS, see #1507 if (n <= 0) return MG_IO_ERR; return n; } @@ -287,7 +287,7 @@ static void read_conn(struct mg_connection *c) { } // there can still be > 16K from last iteration, always mg_tls_recv() m = c->is_tls_hs ? (long) MG_IO_WAIT : mg_tls_recv(c, buf, len); - if (n == MG_IO_ERR) { + if (n == MG_IO_ERR || n == MG_IO_RESET) { // Windows, see #3031 if (c->rtls.len == 0 || m < 0) { // Close only when we have fully drained both rtls and TLS buffers c->is_closing = 1; // or there's nothing we can do about it.