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

Function sal_accept

components/net/sal/src/sal_socket.c:640–691  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
641{
642 int new_socket;
643 struct sal_socket *sock;
644 struct sal_proto_family *pf;
645
646 /* get the socket object by socket descriptor */
647 SAL_SOCKET_OBJ_GET(sock, socket);
648
649 /* check the network interface is up status */
650 SAL_NETDEV_IS_UP(sock->netdev);
651
652 /* check the network interface socket operations */
653 SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept);
654
655 new_socket = pf->skt_ops->accept((int)(size_t)sock->user_data, addr, addrlen);
656 if (new_socket != -1)
657 {
658 int retval;
659 int new_sal_socket;
660 struct sal_socket *new_sock;
661
662 /* allocate a new socket structure and registered socket options */
663 new_sal_socket = socket_new();
664 new_sock = sal_get_socket(new_sal_socket);
665 if (new_sock == RT_NULL)
666 {
667 pf->skt_ops->closesocket(new_socket);
668 return -1;
669 }
670
671 retval = socket_init(sock->domain, sock->type, sock->protocol, &new_sock);
672 if (retval < 0)
673 {
674 pf->skt_ops->closesocket(new_socket);
675 rt_memset(new_sock, 0x00, sizeof(struct sal_socket));
676 /* socket init failed, delete socket */
677 socket_delete(new_sal_socket);
678 LOG_E("New socket registered failed, return error %d.", retval);
679 return -1;
680 }
681
682 /* new socket create by accept should have the same netdev with server*/
683 new_sock->netdev = sock->netdev;
684 /* socket structure user_data used to store the acquired new socket */
685 new_sock->user_data = (void *)(size_t)new_socket;
686
687 return new_sal_socket;
688 }
689
690 return -1;
691}
692
693static void sal_sockaddr_to_ipaddr(const struct sockaddr *name, ip_addr_t *local_ipaddr)
694{

Callers 4

acceptFunction · 0.85
server_thread_entryFunction · 0.85
TC_sal_socket_acceptFunction · 0.85
TC_sal_socket_send_recvFunction · 0.85

Calls 5

socket_newFunction · 0.85
sal_get_socketFunction · 0.85
socket_initFunction · 0.85
rt_memsetFunction · 0.85
socket_deleteFunction · 0.85

Tested by

no test coverage detected