| 350 | } |
| 351 | |
| 352 | int32_t cache_udp_recv(TRWCache* cache, uint32_t fd, struct sockaddr_in* remote_addr) |
| 353 | { |
| 354 | if (NULL == cache) |
| 355 | { |
| 356 | return -1; |
| 357 | } |
| 358 | |
| 359 | int32_t total = 0; |
| 360 | for (uint32_t i = 0; i < 100; i++) |
| 361 | { |
| 362 | TSkBuffer* item = alloc_sk_buffer(cache->pool); |
| 363 | if (NULL == item) |
| 364 | { |
| 365 | return -2; |
| 366 | } |
| 367 | |
| 368 | socklen_t addr_len = sizeof(*remote_addr); |
| 369 | mt_hook_syscall(recvfrom); |
| 370 | int32_t rc = ff_hook_recvfrom(fd, item->data, item->size, 0, (struct sockaddr*)remote_addr, &addr_len); |
| 371 | if (rc <= 0) |
| 372 | { |
| 373 | free_sk_buffer(cache->pool, item); |
| 374 | |
| 375 | if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) |
| 376 | { |
| 377 | break; |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | MTLOG_ERROR("recvfrom failed, fd[%d] ret %d[%m]", fd, rc); |
| 382 | return -3; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | item->data_len += rc; |
| 387 | cache_append_buffer(cache, item); |
| 388 | total += rc; |
| 389 | } |
| 390 | |
| 391 | return total; |
| 392 | } |
| 393 | |
| 394 | int32_t cache_tcp_recv(TRWCache* cache, uint32_t fd) |
| 395 | { |
no test coverage detected