This seems like a really simple task, so bear with me. I'm trying to extend a server which serves up files and webpages. Currently the server gets an HTTP request, parses it, and calls a function called sendFile:
void sendFile(ostream& ostr, std::string filename) {
std::ifstream ifs(filename.c_str(), std::ios_base::binary);
ostr << ifs.rdbuf();
}
This scheme currently works fine for text files like javascript and css which are in the same directory as the server binary. But when I try to serve up a png file, the browser sits forever. It seems like the difference is that the png file is not a text file, but if this is indeed the problem, what should I be using instead of ifstream? I see that the std::ios_base::binary flag is specified.
Thanks!