///////////////////////////////////////////////////////
| 617 | |
| 618 | //////////////////////////////////////////////////////////// |
| 619 | void Ftp::DataChannel::send(std::istream& stream) |
| 620 | { |
| 621 | // Send data |
| 622 | std::array<char, 1024> buffer{}; |
| 623 | std::size_t count = 0; |
| 624 | |
| 625 | for (;;) |
| 626 | { |
| 627 | // read some data from the stream |
| 628 | stream.read(buffer.data(), buffer.size()); |
| 629 | |
| 630 | if (!stream.good() && !stream.eof()) |
| 631 | { |
| 632 | err() << "FTP Error: Reading from the file has failed" << std::endl; |
| 633 | break; |
| 634 | } |
| 635 | |
| 636 | count = static_cast<std::size_t>(stream.gcount()); |
| 637 | |
| 638 | if (count > 0) |
| 639 | { |
| 640 | // we could read more data from the stream: send them |
| 641 | if (m_dataSocket.send(buffer.data(), count) != Socket::Status::Done) |
| 642 | break; |
| 643 | } |
| 644 | else |
| 645 | { |
| 646 | // no more data: exit the loop |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | // Close the data socket |
| 652 | m_dataSocket.disconnect(); |
| 653 | } |
| 654 | |
| 655 | } // namespace sf |
no test coverage detected