Need another pair of eyes to figure this one out
From: Andrew Falanga (falandr_at_hp.com)
Date: 07/26/04
- Next message: Ben Cottrell: "Re: 2 .cpp files"
- Previous message: newbiecpp: "Vector reallocation"
- Next in thread: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: B. v Ingen Schenau: "Re: Need another pair of eyes to figure this one out"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Jul 2004 14:58:53 -0600
This isn't an earth shattering problem, but it is annoying. I'm writing
some class libraries and in doing so am using some driver programs to
test the libraries and see if I'm doing it right.
At one point, I'm opening a file descriptor and also opening a file that
I want to write (in binary) to this descriptor. So that I can watch the
progress of the write, I have embedded in the loop code to show how much
is written and how much is left. Obviously, when completed the final
write to stdout should be the files total size sent with 0 bytes
remaining. However, that's not what I'm getting. So without further
ado, here (in skeleton form) is what I have:
#include <iostream>
#include <fstream>
// lot's more headers because the fd I'm writing to a socket
int main() {
char m[1024]; // in my code this 1024 is #defined
int sock = 0;
// because this is a driver ap, I'm not checking these returns
std::ifstream fin("input.file", std::ios::binary);
// here I would assign a descriptor to sock
int bSent = 0, bRemain = 0;
int read; // for bytes read during last file op
fin.seekg(0, std::ios::end);
bRemain = fin.tellg();
fin.seekg(0, std::ios::beg);
std::cout << "File size is: " << bRemain << std::endl;
while( !fin.eof() ) {
fin.read(m, 1024);
read = fin.gcount();
// placing data on socket
bSent += read, bRemain -= read;
std::cout << "bytes sent: " << bSent
<< "bytes left: " << bRemain << "\r";
std::cout.flush();
}
// close stuff here
return 0;
}
Now, when this is done one would expect to see:
File size is : 30933149
Bytes sent: 30933149 Bytes remaining: 0
However, what I'm getting is:
File size is: 30933149
Bytes sent: 30933149 Bytes remaining: 05717951
What's wrong with my math up there? I'm to the point where I need
someone else to help spot my simple error, I'm really sure it is simple.
---------------------------------------------
Andrew R. Falanga (a non-HP employee)
Hewlett-Packard Company
11311 Chinden Blvd.
Boise, Idaho
---------------------------------------------
Please note: The e-mail address is purposely
mangled. I do not wish my account at HP to
become a spam haven.
- Next message: Ben Cottrell: "Re: 2 .cpp files"
- Previous message: newbiecpp: "Vector reallocation"
- Next in thread: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: Alwyn: "Re: Need another pair of eyes to figure this one out"
- Reply: B. v Ingen Schenau: "Re: Need another pair of eyes to figure this one out"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|