The attached patch (against xmlrpcpp-0.7) adds the
ability to turn on async I/O notification signals on
all file descriptors that are watched by a
XmlRpcServer. This allows the user code to register a
signal handler for the specified signal which will get
called whenever there is some activity on any of the
sockets associated with the XmlRpcServer.
In my case, I use this signal handler to set a flag
"xmlrpcNeedsAttention" that will make sure the
XmlRpcServer::work() method will be called soon. This
behavior is useful for servers whose main purpose is
really to do something else, but that also want to be
able to serve XmlRpc requests without undue overhead of
calling work(0) in polling mode.
The code was developed and tested on a RH Linux 7.2
system with GCC 3.1.
Here is the additional code outside of the library to
make use of this feature:
------------------------------------------------------
static bool xmlrpcNeedsAttention = false;
// signal handler for getting server attention
void IoAttention(int signo)
{
xmlrpcNeedsAttention = true;
}
main() {
...
// create a XML-RPC server
xmlrpcServer = new XmlRpc::XmlRpcServer;
xmlrpcServer->bindAndListen(SERVER_PORT);
struct sigaction action;
action.sa_sigaction = IoAttention;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_RESTART;
// SIGIO is delivered for async I/O notification
if (sigaction(SIGIO, &action, NULL) != 0) {
cerr << "can't install signal handler for SIGIO" <<
endl;
exit(1);
}
// turn on generation of async I/O events
xmlrpcServer->setAsyncIo(SIGIO);
...
while (some_stop_condition) {
while ( ! xmlrpmNeedsAttention) {
... the *real* work ...
}
if (xmlrpcNeedsAttention) {
xmlrpcNeedsAttention = false;
xmlrpcServer->work(0);
}
}
...
}
context diff against xmlrpcpp v. 0.7
Logged In: YES
user_id=42402
I can see how this would be useful.
Ideally, it would work on windows as well. I will look into it
further to see if the windows async io events can be used
somehow...