An example that shows how to set up a basic librpc server and register methods on it.
To run with the default URI: ./build/examples/server/example-server To specify the URI: ./build/examples/server/example-server unix://test2.sock Note that the unix domain socket example requires that client and server be run from the same directory specifying the same socket.
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <glib.h>
#ifndef __unused
#define __unused __attribute__((unused))
#endif
static void
rpc_server_event_t event)
{
const char *addr;
if (event == RPC_SERVER_CLIENT_CONNECT)
printf("client %s connected\n", addr);
if (event == RPC_SERVER_CLIENT_DISCONNECT)
printf("client %s disconnected\n", addr);
}
{
(void)cookie;
}
int
main(int argc, const char *argv[])
{
__block GRand *rand = g_rand_new();
__block gint setcnt = g_rand_int_range(rand, 50, 500);
__block char *strg = g_malloc(27);
NULL, hello);
NULL, ^(
void *cookie __unused,
rpc_object_t args __unused) {
});
NULL, ^(
void *cookie __unused,
rpc_object_t args __unused) {
sleep(5);
});
NULL, ^(
void *cookie __unused,
rpc_object_t args __unused) {
});
strcpy(strg, "abcdefghijklmnopqrstuvwxyz");
int cnt = 0;
gint i;
while (cnt < setcnt) {
cnt++;
i = g_rand_int_range (rand, 0, 26);
strg + i, (int64_t)(26-i), (int64_t)cnt);
fprintf(stderr, "returning %s, %d letters, %d of %d\n",
fprintf(stderr, "yield failed\n");
}
}
});
if (argc > 1)
else
if (srv == NULL) {
fprintf(stderr, "Cannot create server: %s\n",
return (1);
}
sleep(2);
printf("Resuming server now\n");
pause();
return (0);
}