| 1534 | namespace internal { |
| 1535 | |
| 1536 | Future<Nothing> send(network::Socket socket, Encoder* encoder) |
| 1537 | { |
| 1538 | size_t* size = new size_t(0); |
| 1539 | return loop( |
| 1540 | None(), |
| 1541 | [=]() { |
| 1542 | switch (encoder->kind()) { |
| 1543 | case Encoder::DATA: { |
| 1544 | const char* data = static_cast<DataEncoder*>(encoder)->next(size); |
| 1545 | return socket.send(data, *size); |
| 1546 | } |
| 1547 | case Encoder::FILE: { |
| 1548 | off_t offset = 0; |
| 1549 | int_fd fd = static_cast<FileEncoder*>(encoder)->next(&offset, size); |
| 1550 | return socket.sendfile(fd, offset, *size); |
| 1551 | } |
| 1552 | } |
| 1553 | UNREACHABLE(); |
| 1554 | }, |
| 1555 | [=](size_t length) -> ControlFlow<Nothing> { |
| 1556 | // Update the encoder with the amount sent. |
| 1557 | encoder->backup(*size - length); |
| 1558 | |
| 1559 | // See if there is any more of the message to send. |
| 1560 | if (encoder->remaining() != 0) { |
| 1561 | return Continue(); |
| 1562 | } |
| 1563 | |
| 1564 | return Break(); |
| 1565 | }) |
| 1566 | .onAny([=]() { |
| 1567 | delete size; |
| 1568 | }); |
| 1569 | } |
| 1570 | |
| 1571 | |
| 1572 | Future<Nothing> send( |
no test coverage detected