Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTTClient: Fix MQTTClient_cycle for handle socket 0 correct #1395

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -2557,15 +2557,15 @@ static MQTTPacket* MQTTClient_cycle(SOCKET* sock, ELAPSED_TIME_TYPE timeout, int
/* 0 from getReadySocket indicates no work to do, rc -1 == error */
#endif
start = MQTTTime_start_clock();
*sock = Socket_getReadySocket(0, (int)timeout, socket_mutex, rc);
*sock = Socket_getReadySocket(0, (int)timeout, socket_mutex, &rc1);
*rc = rc1;
if (*sock == 0 && timeout >= 100L && MQTTTime_elapsed(start) < (int64_t)10)
if (*sock < 0 && timeout >= 100L && MQTTTime_elapsed(start) < (int64_t)10)
MQTTTime_sleep(100L);
#if defined(OPENSSL)
}
#endif
Thread_lock_mutex(mqttclient_mutex);
if (*sock > 0 && rc1 == 0)
if (*sock >= 0 && rc1 == 0)
{
MQTTClients* m = NULL;
if (ListFindItem(handles, sock, clientSockCompare) != NULL)
Expand Down
18 changes: 9 additions & 9 deletions src/Socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void Socket_outInitialize(void)
SocketBuffer_initialize();
mod_s.connect_pending = ListInitialize();
mod_s.write_pending = ListInitialize();

#if defined(USE_SELECT)
mod_s.clientsds = ListInitialize();
mod_s.cur_clientsds = NULL;
Expand Down Expand Up @@ -387,7 +387,7 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*
Thread_lock_mutex(mutex);
if (mod_s.clientsds->count == 0)
goto exit;

if (more_work)
timeout_ms = 0;
else if (timeout >= 0)
Expand Down Expand Up @@ -416,7 +416,7 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*
memcpy((void*)&(mod_s.rset), (void*)&(mod_s.rset_saved), sizeof(mod_s.rset));
memcpy((void*)&(pwset), (void*)&(mod_s.pending_wset), sizeof(pwset));
maxfdp1_saved = mod_s.maxfdp1;

if (maxfdp1_saved == 0)
{
sock = 0;
Expand Down Expand Up @@ -484,11 +484,11 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*
* be used for the select
* @param timeout the timeout to be used in ms
* @param rc a value other than 0 indicates an error of the returned socket
* @return the socket next ready, or 0 if none is ready
* @return the socket next ready, or -1 if none is ready
*/
SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int* rc)
{
SOCKET sock = 0;
SOCKET sock = -1;
*rc = 0;
int timeout_ms = 1000;

Expand Down Expand Up @@ -553,7 +553,7 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*

if (mod_s.saved.nfds == 0)
{
sock = 0;
sock = -1;
goto exit; /* no work to do */
}

Expand All @@ -578,7 +578,7 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*

if (rc1 == 0 && *rc == 0)
{
sock = 0;
sock = -1;
goto exit; /* no work to do */
}

Expand All @@ -593,7 +593,7 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*

*rc = 0;
if (mod_s.saved.cur_fd == -1)
sock = 0;
sock = -1;
else
{
sock = mod_s.saved.fds_read[mod_s.saved.cur_fd].fd;
Expand Down Expand Up @@ -1389,7 +1389,7 @@ int Socket_continueWrites(fd_set* pwset, SOCKET* sock, mutex_type mutex)
#else
/**
* Continue any outstanding socket writes

* @param sock in case of a socket error contains the affected socket
* @return completion code, 0 or SOCKET_ERROR
*/
Expand Down