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

Function at_connect

components/net/at/at_socket/at_socket.c:891–944  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

889#endif
890
891int at_connect(int socket, const struct sockaddr *name, socklen_t namelen)
892{
893 struct at_socket *sock = RT_NULL;
894 ip_addr_t remote_addr;
895 uint16_t remote_port = 0;
896 char ipstr[16] = { 0 };
897 int result = 0;
898
899 if (name == RT_NULL || namelen == 0)
900 {
901 rt_set_errno(EINVAL);
902 return -1;
903 }
904
905 sock = at_get_socket(socket);
906 if (sock == RT_NULL)
907 {
908 rt_set_errno(ENXIO);
909 return -1;
910 }
911
912 if (sock->state != AT_SOCKET_OPEN)
913 {
914 LOG_E("Socket(%d) connect state is %d.", sock->socket, sock->state);
915 rt_set_errno(EPERM);
916 result = -1;
917 goto __exit;
918 }
919
920 /* get IP address and port by socketaddr structure */
921 socketaddr_to_ipaddr_port(name, &remote_addr, &remote_port);
922 ipaddr_to_ipstr(name, ipstr);
923
924 if (sock->ops->at_connect(sock, ipstr, remote_port, sock->type, RT_TRUE) < 0)
925 {
926 rt_set_errno(EIO);
927 result = -1;
928 goto __exit;
929 }
930
931 sock->state = AT_SOCKET_CONNECT;
932
933__exit:
934 if (result < 0)
935 {
936 at_do_event_changes(sock, AT_EVENT_ERROR, RT_TRUE);
937 }
938 else
939 {
940 at_do_event_changes(sock, AT_EVENT_SEND, RT_TRUE);
941 }
942
943 return result;
944}
945
946#ifdef AT_USING_SOCKET_SERVER
947int at_accept(int socket, struct sockaddr *name, socklen_t *namelen)

Callers

nothing calls this directly

Calls 5

rt_set_errnoFunction · 0.85
at_get_socketFunction · 0.85
ipaddr_to_ipstrFunction · 0.85
at_do_event_changesFunction · 0.85

Tested by

no test coverage detected