void test_server_abyss(void) { TServer abyssServer; printf("Running Abyss XML-RPC server tests...\n"); ServerCreate(&abyssServer, "testserver", 8080, NULL, NULL); testSetHandlers(&abyssServer); ServerSetKeepaliveTimeout(&abyssServer, 60); ServerSetKeepaliveMaxConn(&abyssServer, 10); ServerSetTimeout(&abyssServer, 0); ServerSetAdvertise(&abyssServer, FALSE); ServerFree(&abyssServer); testServerParms(); testObject(); printf("\n"); printf("Abyss XML-RPC server tests done.\n"); }
//---------------------------------------------------------------------------------------- int AcceptExtItem (int sd, ident_t ident, c_tree * ct) { int AcceptedUnits = -1; s_info sub; if (recv (sd, &sub, sizeof (sub), MSG_WAITALL) > 0) // get additional info { if (ident < 0) return 0; // printf("AcceptExtItem(): deads-> Value=%f Time=%d \n",sub.DeadZone,sub.DeadTime); if (ServerAccept (sd, ident) >= 0) // server accept { if (ConnectorAccept (ident, &sub, ct) >= 0) // client accept AcceptedUnits = 1; else { ServerFree (sd, ident); // backup server state fprintf(stderr,"ConnectorAccept ERROR\n"); } } else fprintf(stderr,"ServerAccept ERROR\n"); } //fprintf(stderr,"AcceptItem %s sd=%d ident=%d \n",AcceptedUnits ? "" : "OK",sd,ident); return AcceptedUnits; }
int main(int const argc, const char ** const argv) { struct xmlrpc_method_info3 const methodInfo = { .methodName = "sample.add", .methodFunction = &sample_add, .serverInfo = NULL }; TServer abyssServer; xmlrpc_registry * registryP; xmlrpc_env env; int terminationRequested; /* A boolean value */ const char * error; if (argc-1 != 1) { fprintf(stderr, "You must specify 1 argument: The TCP port number " "on which to listen for XML-RPC calls. " "You specified %d.\n", argc-1); exit(1); } AbyssInit(&error); xmlrpc_env_init(&env); registryP = xmlrpc_registry_new(&env); xmlrpc_registry_add_method3(&env, registryP, &methodInfo); xmlrpc_registry_set_shutdown(registryP, &requestShutdown, &terminationRequested); ServerCreate(&abyssServer, "XmlRpcServer", atoi(argv[1]), NULL, NULL); xmlrpc_server_abyss_set_handlers2(&abyssServer, "/RPC2", registryP); ServerInit(&abyssServer); setupSignalHandlers(); terminationRequested = 0; while (!terminationRequested) { printf("Waiting for next RPC...\n"); ServerRunOnce(&abyssServer); /* This waits for the next connection, accepts it, reads the HTTP POST request, executes the indicated RPC, and closes the connection. */ } ServerFree(&abyssServer); AbyssTerm(); return 0; }
int FreeItem (int sd, ident_t ident) { int res, FreedUnits = -1; if (ServerFree (sd, ident) >= 0) FreedUnits = 1; res = send (sd, &FreedUnits, sizeof (FreedUnits), MSG_DONTWAIT); return res; }
int FreeExtItem (int sd, ident_t ident, c_tree * ct) { int res, FreedUnits = 1; ConnectorFree ( ct, ident ); ServerFree (sd, ident); res = send (sd, &FreedUnits, sizeof (FreedUnits), MSG_DONTWAIT); return res; }
static void * xr_rpcListener (Server *svr) { struct xmlrpc_method_info3 const methodInfo[] = { /* .methodName .methodFunction */ { "svrping", &test_ping, }, /* { "sys.abort", &xr_requestAbort, }, { "sys.shutdown", &xr_requestShutdown, } */ }; register int i = 0; TServer abyssServer; xmlrpc_registry * registryP; xmlrpc_env env; const char * error; extern void xr_serverRunOnce (); extern int xr_requestAbort (); AbyssInit (&error); /* initialize */ xmlrpc_env_init (&env); registryP = xmlrpc_registry_new (&env); if (SRVR_DEBUG) fprintf (stderr, "single_run_server rpcListener ....\n"); /* Setup a test ping method and install the special shutdown handlers. */ for (i=0; i < 1; i++) xmlrpc_registry_add_method3 (&env, registryP, &methodInfo[i]); /* Set default shutdown method. */ xmlrpc_registry_set_shutdown (registryP, &xr_requestShutdown, &svr_done); xr_addServerMethod ("sys.abort", xr_requestAbort, NULL); /* Set the default method we'll use to dispatch calls. */ svr->serverparm.enable_shutdown = (xmlrpc_bool) 1; xmlrpc_registry_set_default_method (&svr->env, (svr->serverparm.registryP = svr->registry = registryP), (xmlrpc_default_method) &xr_defaultMethod, svr); /* Create the server instance. */ ServerCreate (&abyssServer, "XmlRpcServer", svr->serverparm.port_number, NULL, NULL); xmlrpc_server_abyss_set_handlers2 (&abyssServer, "/RPC2", svr->serverparm.registryP); ServerInit (&abyssServer); #ifdef XR_SIGPIPE_IGN xr_setupSigpipeHandlers (); #endif while (! svr_done ) { /* This waits for the next connection, accepts it, reads the * HTTP POST request, executes the indicated RPC, and closes * the connection. ServerRunOnce (&abyssServer); */ // ServerRunOnce(&abyssServer); (void) xr_serverRunOnce (&abyssServer); } ServerFree (&abyssServer); /* shut down */ AbyssTerm (); return ((void *) ERR); }
AbyssServer::~AbyssServer() { ServerFree(&this->cServer); }