|
Boost Users : |
Subject: Re: [Boost-users] Why is asio clobbering my file before it can be sent?
From: Andrew Yancy (andrew732_at_[hidden])
Date: 2011-08-18 10:27:44
Yes, tellg() was just saying that I had reset the file location pointer, sorry about that. However, when I pause using a scanf statement, I can see that the file's contents have disappeared by just looking in the windows file browser (see the updated code below). Anyone know why that would happen? Thanks again~
> I've used the same boilerplate
> boost::asio code for years to send a plain text file
> "foo.txt" from a server back to a client and it has always
> worked fine. Suddenly for no apparent reason, the same
> code I've always used with no problems now deletes the
> contents of foo.txt before it can actually be sent to the
> client. I'm creating foo.txt with a different program
> now, but I don't see how that could make any difference on
> Win32.
>
> Below is the relevant part of the code just before I use
> boost::asio::write to send the contents of foo.txt back to
> the client. The
> contents of the file are somehow lost when the file name and
> size are sent to the client. Anyone know what's going
> on? Is there any other information I can provide to
> shed light on the problem? Thanks very much for any
> help~
>
>
int bar;
std::ifstream source_file("foo.txt", std::ios_base::binary
| std::ios_base::ate);
if (!source_file)
return __LINE__;
size_t file_size = source_file.tellg();
source_file.seekg(0);
scanf("%d", &bar); //foo.txt is OK here
boost::asio::streambuf request;
std::ostream request_stream(&request);
request_stream << return_fn << "\n" <<
file_size << "\n\n";
boost::asio::write(socket, request);
scanf("%d", &bar); //foo.txt exists but has size 0 now
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