MCPcopy Create free account
hub / github.com/F-Stack/f-stack / SendCacheUdp

Method SendCacheUdp

adapter/micro_thread/mt_net.cpp:953–1018  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

951}
952
953int32_t CSockLink::SendCacheUdp(void* data, uint32_t len)
954{
955 mt_hook_syscall(sendto);
956 void* buff = NULL;
957 uint32_t buff_len = 0;
958
959 CNetHandler* item = NULL;
960 CNetHandler* tmp = NULL;
961 struct sockaddr_in dst = {0};
962
963 TAILQ_FOREACH_SAFE(item, &_wait_send, _link_entry, tmp)
964 {
965 item->GetSendData(buff, buff_len);
966 if ((NULL == buff) || (buff_len == 0))
967 {
968 MTLOG_ERROR("get buff ptr invalid, log it");
969 NotifyThread(item, 0);
970 item->SwitchToIdle();
971 continue;
972 }
973
974 int32_t ret = ff_hook_sendto(_fd, buff, buff_len, 0,
975 (struct sockaddr*)this->GetDestAddr(&dst), sizeof(struct sockaddr_in));
976 if (ret == -1)
977 {
978 if ((errno == EINTR) || (errno == EAGAIN) || (errno == EINPROGRESS))
979 {
980 return 0;
981 }
982 else
983 {
984 MTLOG_ERROR("socket send failed, fd %d, errno %d(%s)", _fd,
985 errno, strerror(errno));
986 return -2;
987 }
988 }
989
990 NotifyThread(item, 0);
991 item->SwitchToIdle();
992 }
993
994 if ((data == NULL) || (len == 0))
995 {
996 return 0;
997 }
998
999 int32_t ret = ff_hook_sendto(_fd, data, len, 0,
1000 (struct sockaddr*)this->GetDestAddr(&dst), sizeof(struct sockaddr_in));
1001 if (ret == -1)
1002 {
1003 if ((errno == EINTR) || (errno == EAGAIN) || (errno == EINPROGRESS))
1004 {
1005 return 0;
1006 }
1007 else
1008 {
1009 MTLOG_ERROR("socket send failed, fd %d, errno %d(%s)", _fd,
1010 errno, strerror(errno));

Callers

nothing calls this directly

Calls 4

GetDestAddrMethod · 0.95
GetSendDataMethod · 0.80
SwitchToIdleMethod · 0.80
ff_hook_sendtoFunction · 0.70

Tested by

no test coverage detected