This is for the purpose of a client/server program. The client asks for some data off the server, and receives it. Upon receiving this data from a Boost socket on the client side, I handle this message in a static method called parse_message in a class called client_protocol.
This method, given this specific data, will start a process on an object that is passed to the method as well. I would like, whenever the process that I start, finishes, it should start some other process that will send some results back to the server via the Boost socket again.
Here are some code excerpts.
This is where a message coming in from the server is handled:
class mpqs_client {
..
void mpqs_client::handle_read_body(const boost::system::error_code& error) {
if (!error) {
..
char reply_string[network_message::max_body_length + 1];
// Here I do the call to parse_message to parse the incoming message from the server
strncpy(reply_string,
protocol_.parse_message(read_msg_, &instance_).c_str(),
network_message::max_body_length + 1);
..
} else {
do_close();
}
}
..
};
Here I check on the message type in the client_protocol class:
class client_protocol {
..
static std::string parse_message(network_message& msg, mpqs_sieve **instance_) {
..
switch (type) {
..
// This is the intereseting case, where some data for a polynomial is received
case POLYNOMIAL_DATA:
// We received polynomial coeffecients a, b and c
return set_polynomial_data(m.substr(i+1), instance_);
break;
..
}
}
...
static std::string set_polynomial_data(std::string data, mpqs_sieve **instance_) {
...
// Here I set the polynomial on the object
(*instance_)->set_polynomial(a, b, c);
// This is the process I start. When this finishes,
// I need to send some results, stored in this object,
// to be sent over the Boost socket to the server again
(*instance_)->start();
...
}
};
Any ideas on how I can accomplish sending these results that are computed, via the Boost socket to the server, as soon as the start() function is done? I would like to do so, in as clean and nice manner as possible. My only idea is to pass the mpqs_client object to the start() method, and have it call the socket send when done, but I think this is not a nice approach.
Any ideas? I have looked at Boost::function and Boost::bind but I am not sure if I can use this in my case?