| 1065 | } |
| 1066 | |
| 1067 | int MtFrame::connect(int fd, const struct sockaddr *addr, int addrlen, int timeout) |
| 1068 | { |
| 1069 | MtFrame* mtframe = MtFrame::Instance(); |
| 1070 | utime64_t start = mtframe->GetLastClock(); |
| 1071 | MicroThread* thread = mtframe->GetActiveThread(); |
| 1072 | utime64_t now = 0; |
| 1073 | |
| 1074 | if(fd<0 || !addr || addrlen<1) |
| 1075 | { |
| 1076 | errno = EINVAL; |
| 1077 | MTLOG_ERROR("connect failed, errno: %d (%m)", errno); |
| 1078 | return -10; |
| 1079 | } |
| 1080 | |
| 1081 | int n = 0; |
| 1082 | mt_hook_syscall(connect); |
| 1083 | while ((n = ff_hook_connect(fd, addr, addrlen)) < 0) |
| 1084 | { |
| 1085 | now = mtframe->GetLastClock(); |
| 1086 | if ((int)(now - start) > timeout) |
| 1087 | { |
| 1088 | errno = ETIME; |
| 1089 | return -1; |
| 1090 | } |
| 1091 | |
| 1092 | if (errno == EISCONN) |
| 1093 | { |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | if (errno == EINTR) { |
| 1098 | continue; |
| 1099 | } |
| 1100 | |
| 1101 | if (errno != EINPROGRESS) { |
| 1102 | MTLOG_ERROR("connect failed, errno: %d", errno); |
| 1103 | return -2; |
| 1104 | } |
| 1105 | |
| 1106 | KqueuerObj epfd; |
| 1107 | epfd.SetOsfd(fd); |
| 1108 | epfd.EnableOutput(); |
| 1109 | epfd.SetOwnerThread(thread); |
| 1110 | if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) { |
| 1111 | return -3; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | return n; |
| 1116 | } |
| 1117 | |
| 1118 | int MtFrame::accept(int fd, struct sockaddr *addr, socklen_t *addrlen, int timeout) |
| 1119 | { |
no test coverage detected