Go to the documentation of this file.
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;
void enableIntrospection(bool enabled=true)
Specify whether introspection is enabled or not. Default is not enabled.
virtual void removeConnection(XmlRpcServerConnection *)
Remove a connection from the dispatcher.
static int socket()
Creates a stream (TCP) socket. Returns -1 on failure.
A class to handle XML RPC requests.
virtual std::string help()
void setfd(int fd)
Specify the file descriptor to monitor.
static void log(int level, const char *fmt,...)
Dump messages somewhere.
static const int FREE_FD_BUFFER
static void close(int socket)
Closes a socket.
void setKeepOpen(bool b=true)
Specify whether the file descriptor should be kept open if it is no longer monitored.
bool enoughFreeFDs()
Check if enough number of free file descriptors.
double _accept_retry_time_sec
XmlRpcServerMethod * _methodHelp
void exit()
Exit from work routine.
@ ReadableEvent
data available to read
virtual void close()
Close the owned fd. If deleteOnClose was specified at construction, the object is deleted.
virtual unsigned acceptConnection()
Accept a client connection request.
void addSource(XmlRpcSource *source, unsigned eventMask)
bool _introspectionEnabled
static bool setNonBlocking(int socket)
Sets a stream (TCP) socket to perform non-blocking IO. Returns false on failure.
static const std::string MULTICALL("system.multicall")
void exit()
Temporarily stop processing client requests and exit the work() method.
void listMethods(XmlRpcValue &result)
Introspection support.
virtual XmlRpcServerConnection * createConnection(int socket)
Create a new connection object for processing requests from a specific client.
static int get_port(int socket)
MethodHelp(XmlRpcServer *s)
Abstract class representing a single RPC method.
static const double ACCEPT_RETRY_INTERVAL_SEC
XmlRpcServerMethod * findMethod(const std::string &name) const
Look up a method by name.
static void error(const char *fmt,...)
Dump error messages somewhere.
void removeSource(XmlRpcSource *source)
static int accept(int socket)
Accept a client connection request.
int getfd() const
Return the file descriptor being monitored.
ListMethods(XmlRpcServer *s)
bool bindAndListen(int port, int backlog=5)
std::vector< struct pollfd > pollfds
static const std::string LIST_METHODS("system.listMethods")
void clear()
Clear all sources from the monitored sources list. Sources are closed.
void shutdown()
Close all connections with clients and the socket file descriptor.
virtual unsigned handleEvent(unsigned eventType)
Handle client connection requests.
void work(double msTime)
Process client requests for the specified time.
std::string & name()
Returns the name of the method.
static bool setReuseAddr(int socket)
XmlRpcServer()
Create a server object.
void removeMethod(XmlRpcServerMethod *method)
Remove a command from the RPC server.
void addMethod(XmlRpcServerMethod *method)
Add a command to the RPC server.
virtual ~XmlRpcServer()
Destructor.
static std::string getErrorMsg()
Returns message corresponding to last error.
void setSize(int size)
Specify the size for array values. Array values will grow beyond this size if needed.
static bool bind(int socket, int port)
Bind to a specified port.
static const std::string METHOD_HELP("system.methodHelp")
XmlRpcServerMethod * _listMethods
A class to handle XML RPC requests from a particular client.
void execute(XmlRpcValue &, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
void execute(XmlRpcValue ¶ms, XmlRpcValue &result)
Execute the method. Subclasses must provide a definition for this method.
RPC method arguments and results are represented by Values.
static bool listen(int socket, int backlog)
Set socket in listen mode.
xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
, Jacob Perron
autogenerated on Sat Sep 14 2024 02:59:32