14 #if !defined(_WINDOWS) 15 # include <sys/resource.h> 17 # include <winsock2.h> 26 : _introspectionEnabled(false),
31 _accept_retry_time_sec(0.0)
33 #if !defined(_WINDOWS) 34 struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };
35 unsigned int max_files = 1024;
37 if(getrlimit(RLIMIT_NOFILE, &limit) == 0) {
38 max_files = limit.rlim_max;
39 if( limit.rlim_max == RLIM_INFINITY ) {
46 for(
unsigned int i=0; i<max_files; i++) {
49 pollfds[i].events = POLLIN | POLLPRI | POLLOUT;
87 MethodMap::iterator i =
_methods.find(methodName);
97 MethodMap::const_iterator i =
_methods.find(name);
152 XmlRpcUtil::log(2,
"XmlRpcServer::bindAndListen: server listening on port %d fd %d",
_port, fd);
203 XmlRpcUtil::error(
"XmlRpcServer::acceptConnection: Rejecting client, not enough free file descriptors");
213 XmlRpcUtil::log(2,
"XmlRpcServer::acceptConnection: creating a connection");
225 #if !defined(_WINDOWS) 228 struct rlimit limit = { .rlim_cur = 0, .rlim_max = 0 };
231 if(getrlimit(RLIMIT_NOFILE, &limit) == 0) {
233 if( limit.rlim_max == RLIM_INFINITY ) {
241 if(poll(&
pollfds[0], limit.rlim_cur, 1) >= 0) {
242 for(rlim_t i=0; i<limit.rlim_cur; i++) {
243 if(
pollfds[i].revents & POLLNVAL) {
263 "limit, getrlimit() failed: %s", strerror(errno));
307 static const std::string
LIST_METHODS(
"system.listMethods");
308 static const std::string
METHOD_HELP(
"system.methodHelp");
309 static const std::string
MULTICALL(
"system.multicall");
320 _server->listMethods(result);
323 std::string
help() {
return std::string(
"List all methods available on a server as an array of strings"); }
345 std::string
help() {
return std::string(
"Retrieve the help string for a named method"); }
383 result[i++] = it->first;
A class to handle XML RPC requests from a particular client.
virtual XmlRpcServerConnection * createConnection(int socket)
Create a new connection object for processing requests from a specific client.
int getfd() const
Return the file descriptor being monitored.
static bool setReuseAddr(int socket)
static const double ACCEPT_RETRY_INTERVAL_SEC
XmlRpcServerMethod * findMethod(const std::string &name) const
Look up a method by name.
RPC method arguments and results are represented by Values.
static const std::string METHOD_HELP("system.methodHelp")
std::vector< struct pollfd > pollfds
static int get_port(int socket)
void execute(XmlRpcValue &, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
static int accept(int socket)
Accept a client connection request.
void shutdown()
Close all connections with clients and the socket file descriptor.
void work(double msTime)
Process client requests for the specified time.
bool bindAndListen(int port, int backlog=5)
XmlRpcServer()
Create a server object.
void addMethod(XmlRpcServerMethod *method)
Add a command to the RPC server.
void removeMethod(XmlRpcServerMethod *method)
Remove a command from the RPC server.
void removeSource(XmlRpcSource *source)
void setKeepOpen(bool b=true)
Specify whether the file descriptor should be kept open if it is no longer monitored.
static void error(const char *fmt,...)
Dump error messages somewhere.
virtual unsigned handleEvent(unsigned eventType)
Handle client connection requests.
void clear()
Clear all sources from the monitored sources list. Sources are closed.
virtual ~XmlRpcServer()
Destructor.
static std::string getErrorMsg()
Returns message corresponding to last error.
Abstract class representing a single RPC method.
XmlRpcServerMethod * _listMethods
virtual void close()
Close the owned fd. If deleteOnClose was specified at construction, the object is deleted...
void setfd(int fd)
Specify the file descriptor to monitor.
static bool bind(int socket, int port)
Bind to a specified port.
virtual void removeConnection(XmlRpcServerConnection *)
Remove a connection from the dispatcher.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
static const std::string MULTICALL("system.multicall")
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
A class to handle XML RPC requests.
static bool listen(int socket, int backlog)
Set socket in listen mode.
static const int FREE_FD_BUFFER
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
static void close(int socket)
Closes a socket.
double _accept_retry_time_sec
XmlRpcServerMethod * _methodHelp
void addSource(XmlRpcSource *source, unsigned eventMask)
bool enoughFreeFDs()
Check if enough number of free file descriptors.
virtual std::string help()
static const std::string LIST_METHODS("system.listMethods")
virtual unsigned acceptConnection()
Accept a client connection request.
void exit()
Exit from work routine.
static bool setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
ListMethods(XmlRpcServer *s)
void exit()
Temporarily stop processing client requests and exit the work() method.
void listMethods(XmlRpcValue &result)
Introspection support.
MethodHelp(XmlRpcServer *s)
bool _introspectionEnabled
static void log(int level, const char *fmt,...)
Dump messages somewhere.
std::string & name()
Returns the name of the method.