Skip to content

Commit

Permalink
Merge pull request #374 from cruise2018/iot_link
Browse files Browse the repository at this point in the history
fix:task kill:fix the task kill function
  • Loading branch information
cruise2018 authored May 23, 2020
2 parents a165bca + 96a23bf commit ffce63f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
42 changes: 23 additions & 19 deletions iot_link/network/mqtt/paho_mqtt/port/paho_mqtt_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ typedef struct
void *rcvbuf; //for the mqtt engine used
void *sndbuf;
int stop;
int stoped;
}paho_mqtt_cb_t;

///< waring: the paho mqtt has the opposite return code with normal socket read and write
Expand Down Expand Up @@ -405,8 +406,6 @@ void __mqtt_cb_stop(paho_mqtt_cb_t *cb)
static int __loop_entry(void *arg)
{
paho_mqtt_cb_t *cb;
Network *n = NULL;
MQTTClient *c = NULL;

cb = arg;
while((NULL != cb) && (cb->stop == 0))
Expand All @@ -419,21 +418,7 @@ static int __loop_entry(void *arg)

osal_task_sleep(1);///< when disconnect, this has been killed
}

c = &cb->client;
n = &cb->network;
//net disconnect
LINK_LOG_DEBUG("PAHO TASK TO CLOSE THE NETWORK");
__io_disconnect(n);
//deinit the mqtt
LINK_LOG_DEBUG("PAHO TASK TO CLEAR THE MUTEX");
MQTTClientDeInit(c);
//free the memory
LINK_LOG_DEBUG("PAHO TASK TO FREE THE MEMORY");
osal_free(cb->rcvbuf);
osal_free(cb->sndbuf);
osal_free(cb);
LINK_LOG_DEBUG("PAHO TASK EXIT");
cb->stoped =1;

return 0;
}
Expand Down Expand Up @@ -553,6 +538,7 @@ static void * __connect(mqtt_al_conpara_t *conparam)
goto EXIT_MQTT_MAINTASK;
}
cb->stop = 0;
cb->stoped = 0;
ret = cb;

return ret;
Expand All @@ -579,6 +565,7 @@ static int __disconnect(void *handle)

MQTTClient *c = NULL;
paho_mqtt_cb_t *cb = NULL;
Network *n = NULL;

LINK_LOG_DEBUG("PAHO_EXIT_NOW");
if (NULL == handle)
Expand All @@ -591,12 +578,29 @@ static int __disconnect(void *handle)
LINK_LOG_DEBUG("PAHO_EXIT_SENDISCONNECT MESSAGE");
//mqtt disconnect
(void)MQTTDisconnect(c);

//make the task to exit
LINK_LOG_DEBUG("PAHO MAKE THE TASK TO EXIT");
__mqtt_cb_stop(cb);
osal_task_sleep(1000);

while(0 == cb->stoped) ///< wait for the loop to exit
{
osal_task_sleep(1000);
}
osal_task_kill(cb->task);
c = &cb->client;
n = &cb->network;
//net disconnect
LINK_LOG_DEBUG("PAHO TO CLOSE THE NETWORK");
__io_disconnect(n);
//deinit the mqtt
LINK_LOG_DEBUG("PAHO TO CLEAR THE MUTEX");
MQTTClientDeInit(c);
//free the memory
LINK_LOG_DEBUG("PAHO TO FREE THE MEMORY");
osal_free(cb->rcvbuf);
osal_free(cb->sndbuf);
osal_free(cb);
LINK_LOG_DEBUG("PAHO TASK EXIT");
return 0;
}

Expand Down
7 changes: 7 additions & 0 deletions iot_link/oc/oc_mqtt/oc_mqtt_tiny_v5/oc_mqtt_tiny.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,13 @@ static int tiny_config(oc_mqtt_config_t *config)
{
return ret;
}
if(config->boot_mode != en_oc_mqtt_mode_nobs_static_nodeid_hmacsha256_notimecheck_json )
{
LINK_LOG_DEBUG("BS NOT SUPPORT YET");
ret = en_oc_mqtt_err_gethubaddrtimeout;
return ret;
}

if(config->lifetime == 0)
{
config->lifetime = CN_OC_MQTT_LIFETIMEDEFAULT;
Expand Down
6 changes: 5 additions & 1 deletion iot_link/os/linux/linux_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ static void *__task_create(const char *name,int (*task_entry)(void *args),\

static int __task_kill(void *task)
{
int ret;
pthread_t pid;

pid = (pthread_t)task;
return pthread_cancel(pid);
(void)pthread_cancel(pid); //MAYBE NOT EXIT YET, MAKE SURE YOU ARE THE THREAD OWNER

ret = pthread_join(pid, NULL);
return ret;
}

static void __task_exit()
Expand Down

0 comments on commit ffce63f

Please sign in to comment.