| 143 | } |
| 144 | |
| 145 | int UdpShortConn::RecvData() |
| 146 | { |
| 147 | if (!_action || !_msg_buff) { |
| 148 | MTLOG_ERROR("conn not set action %p, or msg %p, error", _action, _msg_buff); |
| 149 | return -100; |
| 150 | } |
| 151 | |
| 152 | struct sockaddr_in from; |
| 153 | socklen_t fromlen = sizeof(from); |
| 154 | mt_hook_syscall(recvfrom); |
| 155 | int ret = ff_hook_recvfrom(_osfd, _msg_buff->GetMsgBuff(), _msg_buff->GetMaxLen(), |
| 156 | 0, (struct sockaddr*)&from, &fromlen); |
| 157 | if (ret < 0) |
| 158 | { |
| 159 | if ((errno == EINTR) || (errno == EAGAIN) || (errno == EINPROGRESS)) |
| 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | else |
| 164 | { |
| 165 | MTLOG_ERROR("socket recv failed, fd %d, errno %d(%s)", _osfd, |
| 166 | errno, strerror(errno)); |
| 167 | return -2; |
| 168 | } |
| 169 | } |
| 170 | else if (ret == 0) |
| 171 | { |
| 172 | return -1; |
| 173 | } |
| 174 | else |
| 175 | { |
| 176 | _msg_buff->SetHaveRcvLen(ret); |
| 177 | } |
| 178 | |
| 179 | ret = _action->DoInput(); |
| 180 | if (ret > 0) |
| 181 | { |
| 182 | _msg_buff->SetMsgLen(ret); |
| 183 | return ret; |
| 184 | } |
| 185 | else if (ret == 0) |
| 186 | { |
| 187 | return 0; |
| 188 | } |
| 189 | else if (ret == -65535) |
| 190 | { |
| 191 | _msg_buff->SetHaveRcvLen(0); |
| 192 | return 0; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | return -1; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | void UdpShortConn::Reset() |
| 201 | { |
no test coverage detected