| 1019 | } |
| 1020 | |
| 1021 | int MtFrame::sendto(int fd, const void *msg, int len, int flags, const struct sockaddr *to, int tolen, int timeout) |
| 1022 | { |
| 1023 | MtFrame* mtframe = MtFrame::Instance(); |
| 1024 | utime64_t start = mtframe->GetLastClock(); |
| 1025 | MicroThread* thread = mtframe->GetActiveThread(); |
| 1026 | utime64_t now = 0; |
| 1027 | |
| 1028 | if(fd<0 || !msg || len<1) |
| 1029 | { |
| 1030 | errno = EINVAL; |
| 1031 | MTLOG_ERROR("sendto failed, errno: %d (%m)", errno); |
| 1032 | return -10; |
| 1033 | } |
| 1034 | |
| 1035 | int n = 0; |
| 1036 | mt_hook_syscall(sendto); |
| 1037 | while ((n = ff_hook_sendto(fd, msg, len, flags, to, tolen)) < 0) |
| 1038 | { |
| 1039 | now = mtframe->GetLastClock(); |
| 1040 | if ((int)(now - start) > timeout) |
| 1041 | { |
| 1042 | errno = ETIME; |
| 1043 | return -1; |
| 1044 | } |
| 1045 | |
| 1046 | if (errno == EINTR) { |
| 1047 | continue; |
| 1048 | } |
| 1049 | |
| 1050 | if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) { |
| 1051 | MTLOG_ERROR("sendto failed, errno: %d", errno); |
| 1052 | return -2; |
| 1053 | } |
| 1054 | |
| 1055 | KqueuerObj epfd; |
| 1056 | epfd.SetOsfd(fd); |
| 1057 | epfd.EnableOutput(); |
| 1058 | epfd.SetOwnerThread(thread); |
| 1059 | if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) { |
| 1060 | return -3; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | return n; |
| 1065 | } |
| 1066 | |
| 1067 | int MtFrame::connect(int fd, const struct sockaddr *addr, int addrlen, int timeout) |
| 1068 | { |
nothing calls this directly
no test coverage detected