Commit c7451247 authored by Ian Craggs's avatar Ian Craggs

Fix for bug #420851

parent 2bf25bc5
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* Ian Craggs - fix for bug 413429 - connectionLost not called * Ian Craggs - fix for bug 413429 - connectionLost not called
* Ian Craggs - fix for bug# 415042 - using already freed structure * Ian Craggs - fix for bug# 415042 - using already freed structure
* Ian Craggs - fix for bug 419233 - mutexes not reporting errors * Ian Craggs - fix for bug 419233 - mutexes not reporting errors
* Ian Craggs - fix for bug #420851
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -1224,9 +1225,9 @@ thread_return_type WINAPI MQTTAsync_sendThread(void* n) ...@@ -1224,9 +1225,9 @@ thread_return_type WINAPI MQTTAsync_sendThread(void* n)
while (commands->count > 0) while (commands->count > 0)
MQTTAsync_processCommand(); MQTTAsync_processCommand();
#if !defined(WIN32) #if !defined(WIN32)
/*rc =*/ Thread_wait_cond_timeout(send_cond, 1); /*rc =*/ Thread_wait_cond(send_cond, 1);
#else #else
/*rc =*/ Thread_wait_sem_timeout(send_sem, 1); /*rc =*/ Thread_wait_sem(send_sem, 1000);
#endif #endif
MQTTAsync_checkTimeouts(); MQTTAsync_checkTimeouts();
......
This diff is collapsed.
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
* Ian Craggs - fix for bug 413429 - connectionLost not called * Ian Craggs - fix for bug 413429 - connectionLost not called
* Ian Craggs - fix for bug 421103 - trying to write to same socket, in publish/retries * Ian Craggs - fix for bug 421103 - trying to write to same socket, in publish/retries
* Ian Craggs - fix for bug 419233 - mutexes not reporting errors * Ian Craggs - fix for bug 419233 - mutexes not reporting errors
* Ian Craggs - fix for bug #420851
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -1539,15 +1540,15 @@ MQTTPacket* MQTTClient_waitfor(MQTTClient handle, int packet_type, int* rc, long ...@@ -1539,15 +1540,15 @@ MQTTPacket* MQTTClient_waitfor(MQTTClient handle, int packet_type, int* rc, long
{ {
if (packet_type == CONNECT) if (packet_type == CONNECT)
{ {
if ((*rc = Thread_wait_sem(m->connect_sem)) == 0) if ((*rc = Thread_wait_sem(m->connect_sem, timeout)) == 0)
*rc = m->rc; *rc = m->rc;
} }
else if (packet_type == CONNACK) else if (packet_type == CONNACK)
*rc = Thread_wait_sem(m->connack_sem); *rc = Thread_wait_sem(m->connack_sem, timeout);
else if (packet_type == SUBACK) else if (packet_type == SUBACK)
*rc = Thread_wait_sem(m->suback_sem); *rc = Thread_wait_sem(m->suback_sem, timeout);
else if (packet_type == UNSUBACK) else if (packet_type == UNSUBACK)
*rc = Thread_wait_sem(m->unsuback_sem); *rc = Thread_wait_sem(m->unsuback_sem, timeout);
if (*rc == 0 && packet_type != CONNECT && m->pack == NULL) if (*rc == 0 && packet_type != CONNECT && m->pack == NULL)
Log(TRACE_MIN, -1, "waitfor unexpectedly is NULL for client %s, packet_type %d", m->c->clientID, packet_type); Log(TRACE_MIN, -1, "waitfor unexpectedly is NULL for client %s, packet_type %d", m->c->clientID, packet_type);
pack = m->pack; pack = m->pack;
......
This diff is collapsed.
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Ian Craggs - initial implementation * Ian Craggs - initial implementation
* Ian Craggs, Allan Stockdill-Mander - async client updates * Ian Craggs, Allan Stockdill-Mander - async client updates
* Ian Craggs - bug #415042 - start Linux thread as disconnected * Ian Craggs - bug #415042 - start Linux thread as disconnected
* Ian Craggs - fix for bug #420851
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -239,10 +240,10 @@ sem_type Thread_create_sem() ...@@ -239,10 +240,10 @@ sem_type Thread_create_sem()
/** /**
* Wait for a semaphore to be posted, or timeout. * Wait for a semaphore to be posted, or timeout.
* @param sem the semaphore * @param sem the semaphore
* @param timeout the maximum time to wait, in seconds * @param timeout the maximum time to wait, in milliseconds
* @return completion code * @return completion code
*/ */
int Thread_wait_sem_timeout(sem_type sem, int timeout) int Thread_wait_sem(sem_type sem, int timeout)
{ {
/* sem_timedwait is the obvious call to use, but seemed not to work on the Viper, /* sem_timedwait is the obvious call to use, but seemed not to work on the Viper,
* so I've used trywait in a loop instead. Ian Craggs 23/7/2010 * so I've used trywait in a loop instead. Ian Craggs 23/7/2010
...@@ -252,8 +253,8 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout) ...@@ -252,8 +253,8 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout)
#define USE_TRYWAIT #define USE_TRYWAIT
#if defined(USE_TRYWAIT) #if defined(USE_TRYWAIT)
int i = 0; int i = 0;
int interval = 10000; int interval = 10000; /* 10000 microseconds: 10 milliseconds */
int count = (1000000 / interval) * timeout; int count = (1000 / interval) * timeout; /* how many intervals in timeout period */
#else #else
struct timespec ts; struct timespec ts;
#endif #endif
...@@ -261,7 +262,7 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout) ...@@ -261,7 +262,7 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout)
FUNC_ENTRY; FUNC_ENTRY;
#if defined(WIN32) #if defined(WIN32)
rc = WaitForSingleObject(sem, timeout*1000L); rc = WaitForSingleObject(sem, timeout);
#elif defined(USE_TRYWAIT) #elif defined(USE_TRYWAIT)
while (++i < count && (rc = sem_trywait(sem)) != 0) while (++i < count && (rc = sem_trywait(sem)) != 0)
{ {
...@@ -285,17 +286,6 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout) ...@@ -285,17 +286,6 @@ int Thread_wait_sem_timeout(sem_type sem, int timeout)
} }
/**
* Wait for a semaphore to be posted, or timeout after 10 seconds.
* @param sem the semaphore
* @return completion code
*/
int Thread_wait_sem(sem_type sem)
{
return Thread_wait_sem_timeout(sem, 10);
}
/** /**
* Check to see if a semaphore has been posted, without waiting. * Check to see if a semaphore has been posted, without waiting.
* @param sem the semaphore * @param sem the semaphore
...@@ -407,7 +397,7 @@ int Thread_signal_cond(cond_type condvar) ...@@ -407,7 +397,7 @@ int Thread_signal_cond(cond_type condvar)
* Wait with a timeout (seconds) for condition variable * Wait with a timeout (seconds) for condition variable
* @return completion code * @return completion code
*/ */
int Thread_wait_cond_timeout(cond_type condvar, int timeout) int Thread_wait_cond(cond_type condvar, int timeout)
{ {
FUNC_ENTRY; FUNC_ENTRY;
int rc = 0; int rc = 0;
......
This diff is collapsed.
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* Contributors: * Contributors:
* Ian Craggs - initial implementation * Ian Craggs - initial implementation
* Ian Craggs, Allan Stockdill-Mander - async client updates * Ian Craggs, Allan Stockdill-Mander - async client updates
* Ian Craggs - fix for bug #420851
*******************************************************************************/ *******************************************************************************/
#if !defined(THREAD_H) #if !defined(THREAD_H)
...@@ -41,7 +42,7 @@ ...@@ -41,7 +42,7 @@
cond_type Thread_create_cond(); cond_type Thread_create_cond();
int Thread_signal_cond(cond_type); int Thread_signal_cond(cond_type);
int Thread_wait_cond_timeout(cond_type condvar, int timeout); int Thread_wait_cond(cond_type condvar, int timeout);
int Thread_destroy_cond(cond_type); int Thread_destroy_cond(cond_type);
#endif #endif
...@@ -55,8 +56,7 @@ void Thread_destroy_mutex(mutex_type); ...@@ -55,8 +56,7 @@ void Thread_destroy_mutex(mutex_type);
thread_id_type Thread_getid(); thread_id_type Thread_getid();
sem_type Thread_create_sem(); sem_type Thread_create_sem();
int Thread_wait_sem(sem_type sem); int Thread_wait_sem(sem_type sem, int timeout);
int Thread_wait_sem_timeout(sem_type sem, int timeout);
int Thread_check_sem(sem_type sem); int Thread_check_sem(sem_type sem);
int Thread_post_sem(sem_type sem); int Thread_post_sem(sem_type sem);
int Thread_destroy_sem(sem_type sem); int Thread_destroy_sem(sem_type sem);
......
/*******************************************************************************
* Copyright (c) 2009, 2013 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Ian Craggs - initial implementation
* Ian Craggs, Allan Stockdill-Mander - async client updates
*******************************************************************************/
#if !defined(THREAD_H)
#define THREAD_H
#if defined(WIN32)
#include <Windows.h>
#define thread_type HANDLE
#define thread_id_type DWORD
#define thread_return_type DWORD
#define thread_fn LPTHREAD_START_ROUTINE
#define mutex_type HANDLE
#define cond_type HANDLE
#define sem_type HANDLE
#else
#include <pthread.h>
#include <semaphore.h>
#define thread_type pthread_t
#define thread_id_type pthread_t
#define thread_return_type void*
typedef thread_return_type (*thread_fn)(void*);
#define mutex_type pthread_mutex_t*
typedef struct { pthread_cond_t cond; pthread_mutex_t mutex; } cond_type_struct;
typedef cond_type_struct *cond_type;
typedef sem_t *sem_type;
cond_type Thread_create_cond();
int Thread_signal_cond(cond_type);
int Thread_wait_cond(cond_type condvar, int timeout);
int Thread_destroy_cond(cond_type);
#endif
thread_type Thread_start(thread_fn, void*);
mutex_type Thread_create_mutex();
int Thread_lock_mutex(mutex_type);
int Thread_unlock_mutex(mutex_type);
void Thread_destroy_mutex(mutex_type);
thread_id_type Thread_getid();
sem_type Thread_create_sem();
int Thread_wait_sem(sem_type sem, int timeout);
int Thread_check_sem(sem_type sem);
int Thread_post_sem(sem_type sem);
int Thread_destroy_sem(sem_type sem);
#endif
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment