Boost logo

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 13:04:31


Sorry to bother boost-users with a really dumb problem. It turns out I was running the server and client from the same directory, so one was trying to read from the file while the other was trying to write to it. Thanks to those who replied~ --- On Thu, 8/18/11, Andrew Yancy <andrew732_at_[hidden]> wrote: > From: Andrew Yancy <andrew732_at_[hidden]> > Subject: Re: [Boost-users] Why is asio clobbering my file before it can be sent? > To: boost-users_at_[hidden] > Date: Thursday, August 18, 2011, 7:27 AM > 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 mailing list > Boost-users_at_[hidden] > http://lists.boost.org/mailman/listinfo.cgi/boost-users >


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