| 1162 | } |
| 1163 | |
| 1164 | ssize_t MtFrame::read(int fd, void *buf, size_t nbyte, int timeout) |
| 1165 | { |
| 1166 | MtFrame* mtframe = MtFrame::Instance(); |
| 1167 | utime64_t start = mtframe->GetLastClock(); |
| 1168 | MicroThread* thread = mtframe->GetActiveThread(); |
| 1169 | utime64_t now = 0; |
| 1170 | |
| 1171 | if(fd<0 || !buf || nbyte<1) |
| 1172 | { |
| 1173 | errno = EINVAL; |
| 1174 | MTLOG_ERROR("read failed, errno: %d (%m)", errno); |
| 1175 | return -10; |
| 1176 | } |
| 1177 | |
| 1178 | ssize_t n = 0; |
| 1179 | mt_hook_syscall(read); |
| 1180 | while ((n = ff_hook_read(fd, buf, nbyte)) < 0) |
| 1181 | { |
| 1182 | now = mtframe->GetLastClock(); |
| 1183 | if ((int)(now - start) > timeout) |
| 1184 | { |
| 1185 | errno = ETIME; |
| 1186 | return -1; |
| 1187 | } |
| 1188 | |
| 1189 | if (errno == EINTR) { |
| 1190 | continue; |
| 1191 | } |
| 1192 | |
| 1193 | if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) { |
| 1194 | MTLOG_ERROR("read failed, errno: %d", errno); |
| 1195 | return -2; |
| 1196 | } |
| 1197 | |
| 1198 | KqueuerObj epfd; |
| 1199 | epfd.SetOsfd(fd); |
| 1200 | epfd.EnableInput(); |
| 1201 | epfd.SetOwnerThread(thread); |
| 1202 | if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) { |
| 1203 | return -3; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | return n; |
| 1208 | } |
| 1209 | |
| 1210 | ssize_t MtFrame::write(int fd, const void *buf, size_t nbyte, int timeout) |
| 1211 | { |
no test coverage detected