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

Function alloc_socket_by_device

components/net/at/at_socket/at_socket.c:380–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

378}
379
380static struct at_socket *alloc_socket_by_device(struct at_device *device, enum at_socket_type type)
381{
382 rt_base_t level;
383 struct at_socket *sock = RT_NULL;
384 char name[RT_NAME_MAX] = {0};
385 int idx = 0;
386
387 if (at_slock == RT_NULL)
388 {
389 /* create AT socket lock */
390 at_slock = rt_mutex_create("at_slock", RT_IPC_FLAG_PRIO);
391 if (at_slock == RT_NULL)
392 {
393 LOG_E("No memory for socket allocation lock!");
394 return RT_NULL;
395 }
396 }
397
398 rt_mutex_take(at_slock, RT_WAITING_FOREVER);
399
400 /* find an empty at socket entry */
401 if (device->class->socket_ops->at_socket != RT_NULL)
402 {
403 idx = device->class->socket_ops->at_socket(device, type);
404 }
405 else
406 {
407 for (idx = 0; idx < device->class->socket_num && device->sockets[idx].magic == AT_SOCKET_MAGIC; idx++);
408 }
409
410 /* can't find an empty protocol family entry */
411 if (idx < 0 || idx >= device->class->socket_num)
412 {
413 LOG_E("can't find an empty protocol family entry.");
414 goto __err;
415 }
416
417 sock = &(device->sockets[idx]);
418 /* the socket descriptor is the number of sockte lists */
419 sock->socket = idx;
420 /* the socket operations is the specify operations of the device */
421 sock->ops = device->class->socket_ops;
422 /* the user-data is the at device socket descriptor */
423 sock->user_data = (void *) idx;
424 sock->device = (void *) device;
425 sock->magic = AT_SOCKET_MAGIC;
426 sock->state = AT_SOCKET_NONE;
427 sock->rcvevent = RT_NULL;
428 sock->sendevent = RT_NULL;
429 sock->errevent = RT_NULL;
430
431 rt_slist_init(&(sock->list));
432 level = rt_hw_interrupt_disable();
433 rt_slist_insert(&_socket_list, &(sock->list));
434 rt_hw_interrupt_enable(level);
435
436 rt_slist_init(&sock->recvpkt_list);
437#ifdef SAL_USING_POSIX

Callers 2

alloc_socketFunction · 0.85
at_bindFunction · 0.85

Calls 12

rt_mutex_createFunction · 0.85
rt_mutex_takeFunction · 0.85
rt_slist_initFunction · 0.85
rt_slist_insertFunction · 0.85
rt_wqueue_initFunction · 0.85
rt_snprintfFunction · 0.85
rt_sem_createFunction · 0.85
rt_sem_controlFunction · 0.85
rt_mutex_releaseFunction · 0.85
free_socketFunction · 0.70
rt_hw_interrupt_disableFunction · 0.50
rt_hw_interrupt_enableFunction · 0.50

Tested by

no test coverage detected