Skip to content

Commit d203e38

Browse files
authored
Merge pull request #1753 from Lawlieta/chenyong
[net][at] Modify 'AT+CLOSE' processing method
2 parents 07ec7e6 + 02c1f0c commit d203e38

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

components/net/at/at_socket/at_socket.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ int at_closesocket(int socket)
385385
return -1;
386386
}
387387

388+
/* deal with TCP server actively disconnect */
389+
rt_thread_delay(rt_tick_from_millisecond(100));
390+
388391
sock = at_get_socket(socket);
389392
if (sock == RT_NULL)
390393
{
@@ -401,10 +404,13 @@ int at_closesocket(int socket)
401404
if (at_dev_ops->at_closesocket(socket) != 0)
402405
{
403406
LOG_E("AT socket (%d) closesocket failed!", socket);
407+
free_socket(sock);
408+
return -1;
404409
}
405410
}
406411

407-
return free_socket(sock);
412+
free_socket(sock);
413+
return 0;
408414
}
409415

410416
int at_shutdown(int socket, int how)
@@ -427,10 +433,13 @@ int at_shutdown(int socket, int how)
427433
if (at_dev_ops->at_closesocket(socket) != 0)
428434
{
429435
LOG_E("AT socket (%d) shutdown failed!", socket);
436+
free_socket(sock);
437+
return -1;
430438
}
431439
}
432440

433-
return free_socket(sock);
441+
free_socket(sock);
442+
return 0;
434443
}
435444

436445
int at_bind(int socket, const struct sockaddr *name, socklen_t namelen)

components/net/at/include/at.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#ifdef __cplusplus
3232
extern "C" {
3333
#endif
34-
#define AT_SW_VERSION "1.0.0"
34+
35+
#define AT_SW_VERSION "1.0.1"
3536
#define AT_SW_VERSION_NUM 0x10000
3637

3738
#define DBG_ENABLE

components/net/at/src/at_client.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,14 @@ int at_obj_exec_cmd(at_client_t client, at_response_t resp, const char *cmd_expr
290290
rt_err_t result = RT_EOK;
291291
const char *cmd = RT_NULL;
292292

293-
RT_ASSERT(client);
294293
RT_ASSERT(cmd_expr);
295294

295+
if (client == RT_NULL)
296+
{
297+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
298+
return -RT_ERROR;
299+
}
300+
296301
rt_mutex_take(client->lock, RT_WAITING_FOREVER);
297302

298303
client->resp_status = AT_RESP_OK;
@@ -348,8 +353,8 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
348353

349354
if (client == RT_NULL)
350355
{
351-
LOG_E("Input AT Client is NULL, please create or get AT Client!");
352-
return RT_NULL;
356+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
357+
return -RT_ERROR;
353358
}
354359

355360
resp = at_create_resp(16, 0, rt_tick_from_millisecond(500));
@@ -400,13 +405,19 @@ int at_client_obj_wait_connect(at_client_t client, rt_uint32_t timeout)
400405
* @param buf send data buffer
401406
* @param size send fixed data size
402407
*
403-
* @return send data size
408+
* @return >0: send data size
409+
* =0: send failed
404410
*/
405411
rt_size_t at_client_obj_send(at_client_t client, const char *buf, rt_size_t size)
406412
{
407-
RT_ASSERT(client);
408413
RT_ASSERT(buf);
409414

415+
if (client == RT_NULL)
416+
{
417+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
418+
return 0;
419+
}
420+
410421
#ifdef AT_PRINT_RAW_CMD
411422
at_print_raw_cmd("send", buf, size);
412423
#endif
@@ -436,16 +447,22 @@ static char at_client_getchar(at_client_t client)
436447
*
437448
* @note this function can only be used in execution function of URC data
438449
*
439-
* @return success receive data size
450+
* @return >0: receive data size
451+
* =0: receive failed
440452
*/
441453
rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size)
442454
{
443455
rt_size_t read_idx = 0;
444456
char ch;
445457

446-
RT_ASSERT(client);
447458
RT_ASSERT(buf);
448459

460+
if (client == RT_NULL)
461+
{
462+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
463+
return 0;
464+
}
465+
449466
while (1)
450467
{
451468
if (read_idx < size)
@@ -475,7 +492,11 @@ rt_size_t at_client_obj_recv(at_client_t client, char *buf, rt_size_t size)
475492
*/
476493
void at_obj_set_end_sign(at_client_t client, char ch)
477494
{
478-
RT_ASSERT(client);
495+
if (client == RT_NULL)
496+
{
497+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
498+
return;
499+
}
479500

480501
client->end_sign = ch;
481502
}
@@ -491,6 +512,12 @@ void at_obj_set_urc_table(at_client_t client, const struct at_urc *urc_table, rt
491512
{
492513
rt_size_t idx;
493514

515+
if (client == RT_NULL)
516+
{
517+
LOG_E("input AT Client object is NULL, please create or get AT Client object!");
518+
return;
519+
}
520+
494521
for (idx = 0; idx < table_sz; idx++)
495522
{
496523
RT_ASSERT(urc_table[idx].cmd_prefix);

0 commit comments

Comments
 (0)