| 1018 | } |
| 1019 | |
| 1020 | int32_t CSockLink::SendCacheTcp(void* data, uint32_t len) |
| 1021 | { |
| 1022 | void* buff = NULL; |
| 1023 | uint32_t buff_len = 0; |
| 1024 | struct iovec iov[64]; |
| 1025 | int32_t count = 0; |
| 1026 | CNetHandler* item = NULL; |
| 1027 | CNetHandler* tmp = NULL; |
| 1028 | |
| 1029 | TAILQ_FOREACH_SAFE(item, &_wait_send, _link_entry, tmp) |
| 1030 | { |
| 1031 | item->GetSendData(buff, buff_len); |
| 1032 | iov[count].iov_base = buff; |
| 1033 | iov[count].iov_len = (int32_t)buff_len; |
| 1034 | count++; |
| 1035 | if (count >= 64) |
| 1036 | { |
| 1037 | break; |
| 1038 | } |
| 1039 | } |
| 1040 | if ((count < 64) && (data != NULL)) |
| 1041 | { |
| 1042 | iov[count].iov_base = data; |
| 1043 | iov[count].iov_len = (int32_t)len; |
| 1044 | count++; |
| 1045 | } |
| 1046 | |
| 1047 | ssize_t bytes = writev(_fd, iov, count); |
| 1048 | if (bytes < 0) |
| 1049 | { |
| 1050 | if ((errno == EAGAIN) || (errno == EINTR)) |
| 1051 | { |
| 1052 | return 0; |
| 1053 | } |
| 1054 | else |
| 1055 | { |
| 1056 | MTLOG_ERROR("socket writev failed, fd %d, errno %d(%s)", _fd, |
| 1057 | errno, strerror(errno)); |
| 1058 | return -1; |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | uint32_t send_left = (uint32_t)bytes; |
| 1063 | TAILQ_FOREACH_SAFE(item, &_wait_send, _link_entry, tmp) |
| 1064 | { |
| 1065 | send_left -= item->SkipSendPos(send_left); |
| 1066 | item->GetSendData(buff, buff_len); |
| 1067 | if (buff_len == 0) |
| 1068 | { |
| 1069 | NotifyThread(item, 0); |
| 1070 | item->SwitchToIdle(); |
| 1071 | } |
| 1072 | |
| 1073 | if (send_left == 0) |
| 1074 | { |
| 1075 | break; |
| 1076 | } |
| 1077 | } |
nothing calls this directly
no test coverage detected