@@ -454,18 +454,31 @@ static int at_socket_event_recv(uint32_t event, uint32_t timeout, rt_uint8_t opt
454454static int ec20_socket_close (int socket )
455455{
456456 int result = 0 ;
457+ at_response_t resp = RT_NULL ;
458+
459+ resp = at_create_resp (128 , 0 , RT_TICK_PER_SECOND );
460+ if (!resp )
461+ {
462+ LOG_E ("No memory for response structure!" );
463+ return - RT_ENOMEM ;
464+ }
457465
458466 rt_mutex_take (at_event_lock , RT_WAITING_FOREVER );
459467
460468 /* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
461- result = at_exec_cmd (RT_NULL , "AT+QICLOSE=%d,1" , socket );
469+ result = at_exec_cmd (resp , "AT+QICLOSE=%d,1" , socket );
462470 if (result < 0 )
463471 {
464472 return result ;
465473 }
466474
467475 rt_mutex_release (at_event_lock );
468476
477+ if (resp )
478+ {
479+ at_delete_resp (resp );
480+ }
481+
469482 return result ;
470483}
471484
@@ -487,10 +500,18 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
487500{
488501 int result = 0 , event_result = 0 ;
489502 rt_bool_t retryed = RT_FALSE ;
503+ at_response_t resp = RT_NULL ;
490504
491505 RT_ASSERT (ip );
492506 RT_ASSERT (port >= 0 );
493507
508+ resp = at_create_resp (128 , 0 , 5 * RT_TICK_PER_SECOND );
509+ if (!resp )
510+ {
511+ LOG_E ("No memory for response structure!" );
512+ return - RT_ENOMEM ;
513+ }
514+
494515 /* lock AT socket connect */
495516 rt_mutex_take (at_event_lock , RT_WAITING_FOREVER );
496517
@@ -508,15 +529,15 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
508529 /* contextID = 1 : use same contextID as AT+QICSGP & AT+QIACT */
509530 /* local_port=0 : local port assigned automatically */
510531 /* access_mode = 1 : Direct push mode */
511- if (at_exec_cmd (RT_NULL , "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1" , socket , ip , port ) < 0 )
532+ if (at_exec_cmd (resp , "AT+QIOPEN=1,%d,\"TCP\",\"%s\",%d,0,1" , socket , ip , port ) < 0 )
512533 {
513534 result = - RT_ERROR ;
514535 goto __exit ;
515536 }
516537 break ;
517538
518539 case AT_SOCKET_UDP :
519- if (at_exec_cmd (RT_NULL , "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1" , socket , ip , port ) < 0 )
540+ if (at_exec_cmd (resp , "AT+QIOPEN=1,%d,\"UDP\",\"%s\",%d,0,1" , socket , ip , port ) < 0 )
520541 {
521542 result = - RT_ERROR ;
522543 goto __exit ;
@@ -551,7 +572,11 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
551572 {
552573 LOG_W ("socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry." , socket );
553574 /* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
554- at_exec_cmd (RT_NULL , "AT+QICLOSE=%d,1" , socket );
575+ if (ec20_socket_close < 0 )
576+ {
577+ result = - RT_ERROR ;
578+ goto __exit ;
579+ }
555580 retryed = RT_TRUE ;
556581 goto __retry ;
557582 }
@@ -564,6 +589,11 @@ static int ec20_socket_connect(int socket, char *ip, int32_t port, enum at_socke
564589 /* unlock AT socket connect */
565590 rt_mutex_release (at_event_lock );
566591
592+ if (resp )
593+ {
594+ at_delete_resp (resp );
595+ }
596+
567597 return result ;
568598}
569599
@@ -879,9 +909,9 @@ static void urc_close_func(const char *data, rt_size_t size)
879909 at_evt_cb_set [AT_SOCKET_EVT_CLOSED ](socket , AT_SOCKET_EVT_CLOSED , NULL , 0 );
880910 }
881911
882- /* when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
883- at_exec_cmd (RT_NULL , "AT+QICLOSE=%d,0\r\n" , socket );
884- rt_thread_mdelay (100 );
912+ // / * when TCP socket service is closed, host must send "AT+QICLOSE= <connID>,0" command to close socket */
913+ // at_exec_cmd(RT_NULL, "AT+QICLOSE=%d,0\r\n", socket);
914+ // rt_thread_mdelay(100);
885915}
886916
887917static void urc_recv_func (const char * data , rt_size_t size )
0 commit comments