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

Function at_sendto

components/net/at/at_socket/at_socket.c:1128–1238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1126}
1127
1128int at_sendto(int socket, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
1129{
1130 struct at_socket *sock = RT_NULL;
1131 int len = 0, result = 0;
1132
1133 if (data == RT_NULL || size == 0)
1134 {
1135 LOG_E("AT sendto input data or size error!");
1136 rt_set_errno(EFAULT);
1137 return -1;
1138 }
1139
1140 sock = at_get_socket(socket);
1141 if (sock == RT_NULL)
1142 {
1143 rt_set_errno(ENXIO);
1144 return -1;
1145 }
1146
1147 switch (sock->type)
1148 {
1149 case AT_SOCKET_TCP:
1150 if (sock->state == AT_SOCKET_CLOSED)
1151 {
1152 /* socket passively closed, transmit function return 0 */
1153 result = 0;
1154 goto __exit;
1155 }
1156 else if (sock->state != AT_SOCKET_CONNECT)
1157 {
1158 LOG_E("send data error, current socket (%d) state (%d) is error.", socket, sock->state);
1159 rt_set_errno(ENETUNREACH);
1160 result = -1;
1161 goto __exit;
1162 }
1163
1164 if ((len = sock->ops->at_send(sock, (const char *) data, size, sock->type)) < 0)
1165 {
1166 rt_set_errno(EIO);
1167 result = -1;
1168 goto __exit;
1169 }
1170 break;
1171
1172 case AT_SOCKET_UDP:
1173 if (to == RT_NULL || tolen == 0)
1174 {
1175 rt_set_errno(EFAULT);
1176 result = -1;
1177 goto __exit;
1178 }
1179
1180 /* Inconsistent with the last UDP sending address, reconnect to a new address */
1181 if(sock->state == AT_SOCKET_CONNECT && rt_memcmp(&sock->last_udp_adr, to, sizeof(struct sockaddr)) != 0)
1182 {
1183 if (sock->ops->at_closesocket(sock) != 0)
1184 {
1185 free_socket(sock);

Callers 1

at_sendFunction · 0.85

Calls 8

rt_set_errnoFunction · 0.85
at_get_socketFunction · 0.85
rt_memcmpFunction · 0.85
ipaddr_to_ipstrFunction · 0.85
rt_memcpyFunction · 0.85
at_do_event_changesFunction · 0.85
free_socketFunction · 0.70

Tested by

no test coverage detected