|
Boost Users : |
From: Chris Fairles (chris.fairles_at_[hidden])
Date: 2007-06-13 07:58:06
On 6/12/07, Christopher Kohlhoff <chris_at_[hidden]> wrote:
> Chris Fairles wrote:
> > while (bytes_sent < filesize_) {
> > //i test a file 21200678 bytes long. This tranfers anywhere from
> > 21135097 to 21196000.
> > bytes_sent += data_socket_.send(boost::asio::buffer(file.rdbuf(),
> > std::min(size,filesize_-bytes_sent)));
> >
> > //this always transfers 21204202
> > bytes_sent += data_socket_.send(boost::asio::buffer(file.rdbuf(), size));
> >
> > }
>
> I don't see anything in this loop to consume the data from the ifstream.
>
I'm not exactly sure what you mean by consume?
> I can't say what's wrong with your iostream code, but as send() and write_some()
> can result in a "short send" (i.e. send fewer bytes than you ask it to) you
> might like to use asio::write() instead.
Well you were right about write(). I switched it up to this:
char buf[64];
std::filebuf filebuf;
filebuf.open(filepath_.file_string().c_str(), std::ios::in);
filebuf.pubseekoff (file_offset_, std::ios::beg); //if need be
uint32_t bytes_read = 0;
while (bytes_sent < filesize_) {
bytes_read = filebuf.sgetn(buf, 64);
bytes_sent += boost::asio::write(data_socket_,
boost::asio::buffer(buf, bytes_read));
}
data_socket_.close(); //send eof and await response
boost::asio::async_read_until(control_socket_, response_, "\r\n",
boost::bind(&FTPClient::handleRead, this,
boost::asio::placeholders::error));
and not only does it get the whole file each time, but about 100x
faster. I will have to look into the difference between a
tcp::socket's write(_some) and the free function write as I've used
above.
Thanks for your help.
Chris
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net