Background
I am writing a multi-threaded, websocket server in C++.
Problem
When I try to integrate my HTTP parser, MKFAHTTPRequest Request( std::string( Buffer ) ); gets completely skipped during execution.
I’ve cleaned the project and added -Wall and -Werror (which should tell me that Request is an unused variable, but it doesn’t).
void operator()(){
while( true ){
if( m_Socket->is_open() ){
char Buffer[1024];
boost::system::error_code Error;
std::cout << "MKFAConnection::operator()() - Reading..." << std::endl;
m_Socket->read_some( boost::asio::buffer( Buffer, sizeof( Buffer ) ), Error );
if( !Error ){
// This line is getting skipped!?!?!?
MKFAHttpRequest Request( std::string( Buffer ) );
m_Socket->write_some( boost::asio::buffer( std::string( "Hello World" ) ) );
} else break;
} else break;
}
}
This line doesn’t do what you think it does. You think it defines an object named
Requestof typeMKFAHttpRequestand initializes the object with a temporary object of typestd::string.In fact, it declares a function named
Requestwhich accepts a single parameter of typestd::stringand returns an object of typeMKFAHttpRequest.This is related to (or perhaps an example of) the most vexing parse.
Perhaps one of these will make it better:
Ref: http://en.wikipedia.org/wiki/Most_vexing_parse