MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / free_socket

Function free_socket

components/net/at/at_socket/at_socket.c:322–378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322static int free_socket(struct at_socket *sock)
323{
324 if (at_slock == RT_NULL)
325 {
326 /* create AT socket lock */
327 at_slock = rt_mutex_create("at_slock", RT_IPC_FLAG_PRIO);
328 if (at_slock == RT_NULL)
329 {
330 LOG_E("No memory for socket allocation lock!");
331 return RT_NULL;
332 }
333 }
334
335 rt_mutex_take(at_slock, RT_WAITING_FOREVER);
336 if (sock->recv_notice)
337 {
338 rt_sem_delete(sock->recv_notice);
339 }
340
341 if (sock->recv_lock)
342 {
343 rt_mutex_delete(sock->recv_lock);
344 }
345
346 if (!rt_slist_isempty(&sock->recvpkt_list))
347 {
348 at_recvpkt_all_delete(&sock->recvpkt_list);
349 }
350
351 /* delect socket from socket list */
352 {
353 rt_base_t level;
354 rt_slist_t *node = RT_NULL;
355 struct at_socket *at_sock = RT_NULL;
356
357 level = rt_hw_interrupt_disable();
358
359 rt_slist_for_each(node, &_socket_list)
360 {
361 at_sock = rt_slist_entry(node, struct at_socket, list);
362 if (at_sock && sock->socket == at_sock->socket)
363 {
364 if (at_sock->magic == AT_SOCKET_MAGIC)
365 {
366 rt_slist_remove(&_socket_list, &at_sock->list);
367 break;
368 }
369 }
370 }
371
372 rt_hw_interrupt_enable(level);
373 }
374
375 rt_memset(sock, RT_NULL, sizeof(struct at_socket));
376 rt_mutex_release(at_slock);
377 return 0;
378}
379

Callers 6

alloc_socket_by_deviceFunction · 0.70
at_closesocketFunction · 0.70
at_shutdownFunction · 0.70
at_bindFunction · 0.70
at_recvfromFunction · 0.70
at_sendtoFunction · 0.70

Calls 11

rt_mutex_createFunction · 0.85
rt_mutex_takeFunction · 0.85
rt_sem_deleteFunction · 0.85
rt_mutex_deleteFunction · 0.85
rt_slist_isemptyFunction · 0.85
at_recvpkt_all_deleteFunction · 0.85
rt_slist_removeFunction · 0.85
rt_memsetFunction · 0.85
rt_mutex_releaseFunction · 0.85
rt_hw_interrupt_disableFunction · 0.50
rt_hw_interrupt_enableFunction · 0.50

Tested by

no test coverage detected