Fix busy loop in TLS case

This commit is contained in:
Sergey Lyubka committed 2022-03-14 11:16:41 +00:00
1 parent 3ffb6c046e
commit 02cabcc0ec
5 files changed
+30 -39

No files matched your search

+2 -2
View File
@@ -32,18 +32,18 @@ static bool mg_wouldblock(int n) {
static int mg_net_send(void *ctx, const unsigned char *buf, size_t len) {
int fd = *(int *) ctx;
int n = (int) send(fd, buf, len, 0);
MG_VERBOSE(("n=%d, errno=%d", n, errno));
if (n > 0) return n;
if (mg_wouldblock(n)) return MBEDTLS_ERR_SSL_WANT_WRITE;
MG_DEBUG(("n=%d, errno=%d", n, errno));
return MBEDTLS_ERR_NET_SEND_FAILED;
}
static int mg_net_recv(void *ctx, unsigned char *buf, size_t len) {
int fd = *(int *) ctx;
int n = (int) recv(fd, buf, len, 0);
MG_VERBOSE(("n=%d, errno=%d", n, errno));
if (n > 0) return n;
if (mg_wouldblock(n)) return MBEDTLS_ERR_SSL_WANT_READ;
MG_DEBUG(("n=%d, errno=%d", n, errno));
return MBEDTLS_ERR_NET_RECV_FAILED;
}