| 1116 | } |
| 1117 | |
| 1118 | int MtFrame::accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int timeout) |
| 1119 | { |
| 1120 | MtFrame* mtframe = MtFrame::Instance(); |
| 1121 | utime64_t start = mtframe->GetLastClock(); |
| 1122 | MicroThread* thread = mtframe->GetActiveThread(); |
| 1123 | utime64_t now = 0; |
| 1124 | |
| 1125 | if(fd<0) |
| 1126 | { |
| 1127 | errno = EINVAL; |
| 1128 | MTLOG_ERROR("accept failed, errno: %d (%m)", errno); |
| 1129 | return -10; |
| 1130 | } |
| 1131 | |
| 1132 | int acceptfd = 0; |
| 1133 | mt_hook_syscall(accept); |
| 1134 | while ((acceptfd = ff_hook_accept(fd, addr, addrlen)) < 0) |
| 1135 | { |
| 1136 | now = mtframe->GetLastClock(); |
| 1137 | if ((int)(now - start) > timeout) |
| 1138 | { |
| 1139 | errno = ETIME; |
| 1140 | return -1; |
| 1141 | } |
| 1142 | |
| 1143 | if (errno == EINTR) { |
| 1144 | continue; |
| 1145 | } |
| 1146 | |
| 1147 | if (!((errno == EAGAIN) || (errno == EWOULDBLOCK))) { |
| 1148 | MTLOG_ERROR("accept failed, errno: %d", errno); |
| 1149 | return -2; |
| 1150 | } |
| 1151 | |
| 1152 | KqueuerObj epfd; |
| 1153 | epfd.SetOsfd(fd); |
| 1154 | epfd.EnableInput(); |
| 1155 | epfd.SetOwnerThread(thread); |
| 1156 | if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) { |
| 1157 | return -3; |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | return acceptfd; |
| 1162 | } |
| 1163 | |
| 1164 | ssize_t MtFrame::read(int fd, void *buf, size_t nbyte, int timeout) |
| 1165 | { |
no test coverage detected