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

Function at_accept

components/net/at/at_socket/at_socket.c:947–1001  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

945
946#ifdef AT_USING_SOCKET_SERVER
947int at_accept(int socket, struct sockaddr *name, socklen_t *namelen)
948{
949 struct at_socket *sock = RT_NULL;
950 struct at_socket *new_sock = RT_NULL;
951 char receive_buff[AT_SOCKET_INFO_LEN];
952 ip_addr_t remote_addr;
953 uint16_t remote_port = 0;
954 int new_socket = -1;
955 int result = 0;
956
957 sock = at_get_socket(socket);
958 if (sock == RT_NULL)
959 {
960 rt_set_errno(ENXIO);
961 return -1;
962 }
963
964 if (sock->state != AT_SOCKET_LISTEN)
965 {
966 LOG_E("Socket(%d) connect state is %d.", sock->socket, sock->state);
967 rt_set_errno(EIO);
968 result = -1;
969 goto __exit;
970 }
971
972 /* wait the receive semaphore, waiting for info */
973 if (rt_sem_take(sock->recv_notice, RT_WAITING_FOREVER) != RT_EOK)
974 {
975 rt_set_errno(EAGAIN);
976 result = -1;
977 goto __exit;
978 }
979 else
980 {
981 /* get receive buffer to receiver ring buffer */
982 rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER);
983 at_recvpkt_get(&(sock->recvpkt_list), (char *) &receive_buff, AT_SOCKET_INFO_LEN);
984 rt_mutex_release(sock->recv_lock);
985 at_do_event_changes(sock, AT_EVENT_RECV, RT_FALSE);
986 }
987
988 rt_sscanf(&receive_buff[0], "SOCKET:%d", &new_socket);
989 new_sock = at_get_socket(new_socket);
990 ip4_addr_set_any(&remote_addr);
991 ipaddr_port_to_socketaddr(name, &remote_addr, &remote_port);
992 LOG_D("Accept: [socket :%d, base_socket:%d]", new_socket, (int)new_sock->user_data);
993
994__exit:
995 if (result < 0)
996 {
997 at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE);
998 }
999
1000 return new_sock->socket;
1001}
1002#endif
1003
1004int at_recvfrom(int socket, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)

Callers

nothing calls this directly

Calls 9

at_get_socketFunction · 0.85
rt_set_errnoFunction · 0.85
rt_sem_takeFunction · 0.85
rt_mutex_takeFunction · 0.85
at_recvpkt_getFunction · 0.85
rt_mutex_releaseFunction · 0.85
at_do_event_changesFunction · 0.85
rt_sscanfFunction · 0.85

Tested by

no test coverage detected