diff --git a/lib/plat/esp32/esp32-sockets.c b/lib/plat/esp32/esp32-sockets.c index 67b39a824..7a592d797 100644 --- a/lib/plat/esp32/esp32-sockets.c +++ b/lib/plat/esp32/esp32-sockets.c @@ -82,7 +82,7 @@ lws_plat_check_connection_error(struct lws *wsi) int -lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) +lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) { int optval = 1; socklen_t optlen = sizeof(optval); diff --git a/lib/plat/esp32/private.h b/lib/plat/esp32/private.h index 574c92373..3d32d4460 100644 --- a/lib/plat/esp32/private.h +++ b/lib/plat/esp32/private.h @@ -49,6 +49,7 @@ #define LWS_EINPROGRESS EINPROGRESS #define LWS_EINTR EINTR #define LWS_EISCONN EISCONN + #define LWS_ENOTCONN ENOTCONN #define LWS_EWOULDBLOCK EWOULDBLOCK #define lws_set_blocking_send(wsi) diff --git a/lib/plat/optee/lws-plat-optee.c b/lib/plat/optee/lws-plat-optee.c index f1000182c..84d78bd18 100644 --- a/lib/plat/optee/lws-plat-optee.c +++ b/lib/plat/optee/lws-plat-optee.c @@ -202,7 +202,7 @@ lws_plat_service(struct lws_context *context, int timeout_ms) } int -lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) +lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) { return 0; } diff --git a/lib/plat/optee/private.h b/lib/plat/optee/private.h index 6a49f362d..85137c449 100644 --- a/lib/plat/optee/private.h +++ b/lib/plat/optee/private.h @@ -55,6 +55,7 @@ #define LWS_EINPROGRESS EINPROGRESS #define LWS_EINTR EINTR #define LWS_EISCONN EISCONN + #define LWS_ENOTCONN ENOTCONN #define LWS_EWOULDBLOCK EWOULDBLOCK #define lws_set_blocking_send(wsi) diff --git a/lib/plat/unix/private.h b/lib/plat/unix/private.h index b9e8bfa2c..fcd053568 100644 --- a/lib/plat/unix/private.h +++ b/lib/plat/unix/private.h @@ -125,6 +125,7 @@ #define LWS_EINPROGRESS EINPROGRESS #define LWS_EINTR EINTR #define LWS_EISCONN EISCONN +#define LWS_ENOTCONN ENOTCONN #define LWS_EWOULDBLOCK EWOULDBLOCK #define lws_set_blocking_send(wsi) #define LWS_SOCK_INVALID (-1) diff --git a/lib/plat/unix/unix-sockets.c b/lib/plat/unix/unix-sockets.c index b423eaa1e..bd4c4a6d3 100644 --- a/lib/plat/unix/unix-sockets.c +++ b/lib/plat/unix/unix-sockets.c @@ -66,7 +66,7 @@ lws_send_pipe_choked(struct lws *wsi) int -lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) +lws_plat_set_socket_options(struct lws_vhost *vhost, int fd, int unix_skt) { int optval = 1; socklen_t optlen = sizeof(optval); @@ -81,7 +81,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) (void)fcntl(fd, F_SETFD, FD_CLOEXEC); - if (vhost->ka_time) { + if (!unix_skt && vhost->ka_time) { /* enable keepalive on this socket */ optval = 1; if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, @@ -126,7 +126,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) } #if defined(SO_BINDTODEVICE) - if (vhost->bind_iface && vhost->iface) { + if (!unix_skt && vhost->bind_iface && vhost->iface) { lwsl_info("binding listen skt to %s using SO_BINDTODEVICE\n", vhost->iface); if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, vhost->iface, strlen(vhost->iface)) < 0) { @@ -139,18 +139,18 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd) /* Disable Nagle */ optval = 1; #if defined (__sun) || defined(__QNX__) - if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0) + if (!unix_skt && setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0) return 1; #elif !defined(__APPLE__) && \ !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && \ !defined(__NetBSD__) && \ !defined(__OpenBSD__) && \ !defined(__HAIKU__) - if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0) + if (!unix_skt && setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&optval, optlen) < 0) return 1; #else tcp_proto = getprotobyname("TCP"); - if (setsockopt(fd, tcp_proto->p_proto, TCP_NODELAY, &optval, optlen) < 0) + if (!unix_skt && setsockopt(fd, tcp_proto->p_proto, TCP_NODELAY, &optval, optlen) < 0) return 1; #endif diff --git a/lib/plat/windows/private.h b/lib/plat/windows/private.h index 185f688c6..591a6836d 100644 --- a/lib/plat/windows/private.h +++ b/lib/plat/windows/private.h @@ -39,6 +39,7 @@ #define LWS_EINPROGRESS WSAEINPROGRESS #define LWS_EINTR WSAEINTR #define LWS_EISCONN WSAEISCONN + #define LWS_ENOTCONN WSAENOTCONN #define LWS_EWOULDBLOCK WSAEWOULDBLOCK #define MSG_NOSIGNAL 0 #define SHUT_RDWR SD_BOTH diff --git a/lib/plat/windows/windows-sockets.c b/lib/plat/windows/windows-sockets.c index 99d9f6a01..c168a52d5 100644 --- a/lib/plat/windows/windows-sockets.c +++ b/lib/plat/windows/windows-sockets.c @@ -41,7 +41,8 @@ lws_poll_listen_fd(struct lws_pollfd *fd) } int -lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd) +lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd, + int unix_skt) { int optval = 1; int optlen = sizeof(optval); diff --git a/lib/tls/mbedtls/ssl.c b/lib/tls/mbedtls/ssl.c index e0e134c58..5ff0d870f 100644 --- a/lib/tls/mbedtls/ssl.c +++ b/lib/tls/mbedtls/ssl.c @@ -69,7 +69,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) errno = 0; n = SSL_read(wsi->tls.ssl, buf, len); #if defined(LWS_WITH_ESP32) - if (!n && errno == ENOTCONN) { + if (!n && errno == LWS_ENOTCONN) { lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); return LWS_SSL_CAPABLE_ERROR; } diff --git a/lib/tls/openssl/ssl.c b/lib/tls/openssl/ssl.c index 59250fbc1..2af4a7af9 100644 --- a/lib/tls/openssl/ssl.c +++ b/lib/tls/openssl/ssl.c @@ -210,7 +210,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) errno = 0; n = SSL_read(wsi->tls.ssl, buf, len); #if defined(LWS_WITH_ESP32) - if (!n && errno == ENOTCONN) { + if (!n && errno == LWS_ENOTCONN) { lwsl_debug("%p: SSL_read ENOTCONN\n", wsi); return LWS_SSL_CAPABLE_ERROR; } @@ -227,7 +227,7 @@ lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len) lwsl_debug("%p: SSL_read says %d\n", wsi, n); /* manpage: returning 0 means connection shut down */ - if (!n || (n == -1 && errno == ENOTCONN)) { + if (!n || (n == -1 && errno == LWS_ENOTCONN)) { wsi->socket_is_permanently_unusable = 1; return LWS_SSL_CAPABLE_ERROR;