Fix errno setting on Windows

Closes #3424
This commit is contained in:
Roger A. Light
2026-01-07 15:04:06 +00:00
parent 88b90dd159
commit ae7cf71dcf
4 changed files with 10 additions and 7 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ int http_c__read(struct mosquitto *mosq)
if(read_length == 0){
return MOSQ_ERR_CONN_LOST; /* EOF */
}
WINDOWS_SET_ERRNO();
WINDOWS_SET_ERRNO_RW();
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
return MOSQ_ERR_SUCCESS;
}else{
+5
View File
@@ -77,11 +77,16 @@ typedef int mosq_sock_t;
#ifdef WIN32
# define WINDOWS_SET_ERRNO() \
do{ \
errno = WSAGetLastError(); \
}while(0)
# define WINDOWS_SET_ERRNO_RW() \
if(errno != EAGAIN){ \
errno = WSAGetLastError(); \
}
#else
# define WINDOWS_SET_ERRNO()
# define WINDOWS_SET_ERRNO_RW()
#endif
#define SAFE_PRINT(A) (A)?(A):"null"
+3 -4
View File
@@ -307,8 +307,7 @@ int packet__write(struct mosquitto *mosq)
packet->to_process -= (uint32_t)write_length;
packet->pos += (uint32_t)write_length;
}else{
WINDOWS_SET_ERRNO();
WINDOWS_SET_ERRNO_RW();
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK
#ifdef WIN32
|| errno == WSAENOTCONN
@@ -377,7 +376,7 @@ static int read_header(struct mosquitto *mosq, ssize_t (*func_read)(struct mosqu
if(read_length == 0){
return MOSQ_ERR_CONN_LOST; /* EOF */
}
WINDOWS_SET_ERRNO();
WINDOWS_SET_ERRNO_RW();
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
return MOSQ_ERR_SUCCESS;
}else{
@@ -586,7 +585,7 @@ static int packet__read_single(struct mosquitto *mosq, enum mosquitto_client_sta
mosq->in_packet.to_process -= (uint32_t)read_length;
mosq->in_packet.pos += (uint32_t)read_length;
}else{
WINDOWS_SET_ERRNO();
WINDOWS_SET_ERRNO_RW();
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
if(mosq->in_packet.to_process > 1000){
/* Update last_msg_in time if more than 1000 bytes left to
+1 -2
View File
@@ -64,8 +64,7 @@ Contributors:
static inline int socks5__network_error(struct mosquitto *mosq)
{
WINDOWS_SET_ERRNO();
WINDOWS_SET_ERRNO_RW();
if(errno == EAGAIN || errno == COMPAT_EWOULDBLOCK){
return MOSQ_ERR_SUCCESS;
}else{