diff --git a/lib/plat/esp32/esp32-sockets.c b/lib/plat/esp32/esp32-sockets.c
index 67b39a824029368027126a4bfd7b0caf880c35f1..7a592d797027547d6381e819a97d7981b1f6da12 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 574c92373000246a9c8a2ebd84618973ee42c868..3d32d4460b7b7b2a09bc11342bd2404223648c28 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 f1000182ce1c585d92f8bf1faca0734b84e57c5a..84d78bd1850beac12372f71b850288c9c393210f 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 6a49f362df24ff333361f2bfc807fe95621f2ab1..85137c4498b4c500ef76c4771a24a4eb9bc7b024 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 b9e8bfa2c7601848d33d0a5c58c2407accbd461d..fcd053568be18241298b992e8cc68a35a66842b6 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 b423eaa1effcafa34a66709a5a0fa25af543eb51..bd4c4a6d394c42f92c571803e60ddb6958a3888b 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 185f688c68495867dc659f6ad39fdddf3b3c7828..591a6836d09f1f076f4951904576e706383d2816 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 99d9f6a0198e3ad915fae0cfedfe95a885205d77..c168a52d508191fb6c5eaec48ad596bfc04cc305 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 e0e134c58bc29e35862b5131c1c19cf7a22e7273..5ff0d870fdac06d19b02e975b875dd6cfcc9d2ca 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 59250fbc1c9afccd144d39a0a8cae69219357c32..2af4a7af9f39431e50d9368ddefa78f920a6153c 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;