| 224 | } |
| 225 | |
| 226 | int NS_MICRO_THREAD::mt_multi_sendto(IMtActList& req_list, int timeout) |
| 227 | { |
| 228 | utime64_t start_ms = MtFrame::Instance()->GetLastClock(); |
| 229 | utime64_t end_ms = start_ms + timeout; |
| 230 | utime64_t curr_ms = 0; |
| 231 | |
| 232 | int ret = 0, has_send = 0; |
| 233 | IMtAction* action = NULL; |
| 234 | IMtConnection* net_handler = NULL; |
| 235 | |
| 236 | while (1) |
| 237 | { |
| 238 | IMtActList wait_list; |
| 239 | for (IMtActList::iterator it = req_list.begin(); it != req_list.end(); ++it) |
| 240 | { |
| 241 | action = *it; |
| 242 | if (action->GetErrno() != ERR_NONE) { |
| 243 | continue; |
| 244 | } |
| 245 | |
| 246 | if (action->GetMsgFlag() == MULTI_FLAG_SEND) { |
| 247 | has_send = 1; |
| 248 | continue; |
| 249 | } |
| 250 | |
| 251 | net_handler = action->GetIConnection(); |
| 252 | if (NULL == net_handler) |
| 253 | { |
| 254 | action->SetErrno(ERR_FRAME_ERROR); |
| 255 | MTLOG_ERROR("Invalid param, conn %p null!!", net_handler); |
| 256 | return -2; |
| 257 | } |
| 258 | |
| 259 | ret = net_handler->SendData(); |
| 260 | if (ret == -1) |
| 261 | { |
| 262 | action->SetErrno(ERR_SEND_FAIL); |
| 263 | MTLOG_ERROR("MultiItem msg send error, %d", errno); |
| 264 | continue; |
| 265 | } |
| 266 | else if (ret == 0) |
| 267 | { |
| 268 | wait_list.push_back(action); |
| 269 | continue; |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | action->SetMsgFlag(MULTI_FLAG_SEND); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | curr_ms = MtFrame::Instance()->GetLastClock(); |
| 278 | if (curr_ms > end_ms) |
| 279 | { |
| 280 | MTLOG_DEBUG("send data timeout"); |
| 281 | for (IMtActList::iterator it = wait_list.begin(); it != wait_list.end(); ++it) |
| 282 | { |
| 283 | (*it)->SetErrno(ERR_SEND_FAIL); |
nothing calls this directly
no test coverage detected