| 460 | #undef HTTP_SERVER_SENDALL_AND_BAIL |
| 461 | |
| 462 | Result Receive(const Request* request, void* buffer, uint32_t buffer_size, uint32_t* received_bytes) |
| 463 | { |
| 464 | InternalRequest* internal_req = (InternalRequest*) request->m_Internal; |
| 465 | if (internal_req->m_Result != RESULT_OK) |
| 466 | return internal_req->m_Result; |
| 467 | |
| 468 | uint32_t total = 0; |
| 469 | assert(internal_req->m_TotalReceived >= internal_req->m_ContentOffset); |
| 470 | uint32_t bytes_in_buffer = internal_req->m_TotalReceived - internal_req->m_ContentOffset; |
| 471 | if (bytes_in_buffer > 0) |
| 472 | { |
| 473 | uint32_t to_copy = dmMath::Min(buffer_size, bytes_in_buffer); |
| 474 | memcpy(buffer, internal_req->m_Server->m_Buffer + internal_req->m_ContentOffset, to_copy); |
| 475 | internal_req->m_ContentOffset += to_copy; |
| 476 | total += to_copy; |
| 477 | } |
| 478 | |
| 479 | while (total < buffer_size) |
| 480 | { |
| 481 | void* p = (void*) (((uintptr_t) buffer) + total); |
| 482 | int to_recv = buffer_size - total; |
| 483 | int recv_bytes = 0; |
| 484 | dmSocket::Result r = dmSocket::Receive(internal_req->m_Socket, p, to_recv, &recv_bytes); |
| 485 | if (r == dmSocket::RESULT_TRY_AGAIN) |
| 486 | { |
| 487 | // Ok |
| 488 | } |
| 489 | else if (r == dmSocket::RESULT_OK) |
| 490 | { |
| 491 | total += recv_bytes; |
| 492 | } |
| 493 | else |
| 494 | { |
| 495 | internal_req->m_Result = RESULT_SOCKET_ERROR; |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | internal_req->m_TotalContentReceived += total; |
| 500 | *received_bytes = total; |
| 501 | |
| 502 | return internal_req->m_Result; |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Handle an http-connection |
no test coverage detected