@@ -62,6 +62,7 @@ typedef struct
62
62
MQTTClient client ;
63
63
atiny_param_t atiny_params ;
64
64
char atiny_quit ;
65
+ char bind_quit ;
65
66
} handle_data_t ;
66
67
67
68
static handle_data_t g_atiny_handle ;
@@ -145,13 +146,13 @@ int atiny_param_dup(atiny_param_t *dest, atiny_param_t *src)
145
146
dest -> u .psk .psk_id = (unsigned char * )atiny_strdup ((const char * )(src -> u .psk .psk_id ));
146
147
if (NULL == dest -> u .psk .psk_id )
147
148
goto atiny_param_dup_failed ;
148
- if (src -> u .psk .psk_len < 0 || src -> u .psk .psk_len > MQTT_PSK_MAX_LEN )
149
+ dest -> u .psk .psk_id_len = strlen ((const char * )(src -> u .psk .psk_id ));
150
+ if (NULL == src -> u .psk .psk || src -> u .psk .psk_len < 0 || src -> u .psk .psk_len > MQTT_PSK_MAX_LEN )
149
151
goto atiny_param_dup_failed ;
150
152
dest -> u .psk .psk = (unsigned char * )atiny_malloc (src -> u .psk .psk_len );
151
153
if (NULL == dest -> u .psk .psk )
152
154
goto atiny_param_dup_failed ;
153
155
memcpy (dest -> u .psk .psk , src -> u .psk .psk , src -> u .psk .psk_len );
154
- dest -> u .psk .psk_id_len = src -> u .psk .psk_id_len ;
155
156
dest -> u .psk .psk_len = src -> u .psk .psk_len ;
156
157
break ;
157
158
case CLOUD_SECURITY_TYPE_CA :
@@ -183,12 +184,18 @@ int atiny_init(atiny_param_t *atiny_params, void **phandle)
183
184
return ATINY_ARG_INVALID ;
184
185
}
185
186
187
+ while (1 == g_atiny_handle .bind_quit )
188
+ {
189
+ (void )LOS_TaskDelay (10 );
190
+ }
191
+
186
192
memset ((void * )& g_atiny_handle , 0 , sizeof (handle_data_t ));
187
193
188
194
if (0 != atiny_param_dup (& (g_atiny_handle .atiny_params ), atiny_params ))
189
195
return ATINY_MALLOC_FAILED ;
190
196
191
197
g_atiny_handle .atiny_quit = 0 ;
198
+ g_atiny_handle .bind_quit = 0 ;
192
199
* phandle = & g_atiny_handle ;
193
200
194
201
return ATINY_OK ;
@@ -197,27 +204,21 @@ int atiny_init(atiny_param_t *atiny_params, void **phandle)
197
204
void atiny_deinit (void * phandle )
198
205
{
199
206
handle_data_t * handle ;
200
- MQTTClient * client ;
201
- Network * network ;
202
207
203
208
if (NULL == phandle )
204
209
{
205
210
ATINY_LOG (LOG_FATAL , "Parameter null" );
206
211
return ;
207
212
}
208
213
handle = (handle_data_t * )phandle ;
209
- client = & (handle -> client );
210
- network = client -> ipstack ;
211
214
if (0 == handle -> atiny_quit )
212
215
{
213
216
handle -> atiny_quit = 1 ;
214
- atiny_param_member_free (& (handle -> atiny_params ));
215
- if (client -> mutex ) atiny_mutex_lock (client -> mutex );
216
- device_info_member_free (& (handle -> device_info ));
217
- if (client -> mutex ) atiny_mutex_unlock (client -> mutex );
218
- (void )MQTTDisconnect (client );
219
- MQTTClientDeInit (client );
220
- NetworkDisconnect (network );
217
+ while (0 == handle -> bind_quit )
218
+ {
219
+ (void )LOS_TaskDelay (10 );
220
+ }
221
+ handle -> bind_quit = 0 ;
221
222
}
222
223
223
224
return ;
@@ -618,6 +619,8 @@ int device_info_dup(atiny_device_info_t *dest, atiny_device_info_t *src)
618
619
if (NULL == dest -> will_options )
619
620
goto device_info_dup_failed ;
620
621
622
+ memset (dest -> will_options , 0x0 , sizeof (cloud_will_options_t ));
623
+
621
624
dest -> will_options -> topic_name = atiny_strdup ((const char * )(src -> will_options -> topic_name ));
622
625
if (NULL == dest -> will_options -> topic_name )
623
626
goto device_info_dup_failed ;
@@ -667,39 +670,38 @@ int atiny_isconnected(void *phandle)
667
670
int atiny_bind (atiny_device_info_t * device_info , void * phandle )
668
671
{
669
672
Network n ;
670
- handle_data_t * handle ;
671
- MQTTClient * client ;
673
+ handle_data_t * handle = NULL ;
674
+ MQTTClient * client = NULL ;
672
675
atiny_param_t * atiny_params ;
673
676
atiny_device_info_t * device_info_t ;
674
677
int rc = -1 , conn_failed_cnt = 0 ;
675
678
MQTTPacket_connectData data = MQTTPacket_connectData_initializer ;
676
679
677
- if (( NULL == device_info ) || ( NULL == phandle ) )
680
+ if ( NULL == phandle )
678
681
{
679
682
ATINY_LOG (LOG_FATAL , "Parameter null" );
680
683
return ATINY_ARG_INVALID ;
681
684
}
682
685
683
- if (NULL == device_info -> client_id )
686
+ handle = (handle_data_t * )phandle ;
687
+ client = & (handle -> client );
688
+ atiny_params = & (handle -> atiny_params );
689
+
690
+ if ((NULL == device_info ) || (NULL == device_info -> client_id ))
684
691
{
685
692
ATINY_LOG (LOG_FATAL , "Parameter null" );
686
- return ATINY_ARG_INVALID ;
693
+ goto atiny_bind_quit ;
687
694
}
688
695
689
696
if (device_info -> will_flag == MQTT_WILL_FLAG_TRUE && NULL == device_info -> will_options )
690
697
{
691
698
ATINY_LOG (LOG_FATAL , "Parameter null" );
692
- return ATINY_ARG_INVALID ;
699
+ goto atiny_bind_quit ;
693
700
}
694
701
695
- handle = (handle_data_t * )phandle ;
696
- client = & (handle -> client );
697
- atiny_params = & (handle -> atiny_params );
698
-
699
702
if (0 != device_info_dup (& (handle -> device_info ), device_info ))
700
703
{
701
- atiny_deinit (phandle );
702
- return ATINY_MALLOC_FAILED ;
704
+ goto atiny_bind_quit ;
703
705
}
704
706
device_info_t = & (handle -> device_info );
705
707
@@ -719,7 +721,7 @@ int atiny_bind(atiny_device_info_t *device_info, void *phandle)
719
721
break ;
720
722
case CLOUD_SECURITY_TYPE_CA :
721
723
ATINY_LOG (LOG_INFO , "CLOUD_SECURITY_TYPE_CA unsupported now" );
722
- return ATINY_ARG_INVALID ;
724
+ goto atiny_bind_quit ;
723
725
default :
724
726
ATINY_LOG (LOG_WARNING , "invalid security_typ : %d" , atiny_params -> security_type );
725
727
break ;
@@ -789,6 +791,13 @@ int atiny_bind(atiny_device_info_t *device_info, void *phandle)
789
791
data .cleansession = MQTT_CLEAN_SESSION_FALSE ;
790
792
ATINY_LOG (LOG_ERR , "connect_again" );
791
793
}
794
+ atiny_bind_quit :
795
+ atiny_param_member_free (& (handle -> atiny_params ));
796
+ if (client -> mutex ) atiny_mutex_lock (client -> mutex );
797
+ device_info_member_free (& (handle -> device_info ));
798
+ if (client -> mutex ) atiny_mutex_unlock (client -> mutex );
799
+ MQTTClientDeInit (client );
800
+ handle -> bind_quit = 1 ;
792
801
return ATINY_OK ;
793
802
}
794
803
0 commit comments