Mercurial > nomad > old-fuse
changeset 118:d01f527b9718
client: RPC dispatching code with a mostly correct NOP fs RPC
Technically, the NOP RPC is not correct because it doesn't send back the
command response header.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 17 Oct 2015 19:05:15 -0400 |
parents | 55b2945bcee5 |
children | 1a6520cd3e0d |
files | src/client/CMakeLists.txt src/client/main.c |
diffstat | 2 files changed, 64 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/client/CMakeLists.txt Sat Oct 17 19:00:44 2015 -0400 +++ b/src/client/CMakeLists.txt Sat Oct 17 19:05:15 2015 -0400 @@ -29,6 +29,7 @@ ${TASKQ_LIBRARY} common nomad_objstore + nsl ) install(TARGETS nomad-client DESTINATION bin
--- a/src/client/main.c Sat Oct 17 19:00:44 2015 -0400 +++ b/src/client/main.c Sat Oct 17 19:05:15 2015 -0400 @@ -28,13 +28,76 @@ #include <nomad/types.h> #include <nomad/objstore.h> #include <nomad/connsvc.h> +#include <nomad/rpc_fs.h> #define CLIENT_DAEMON_PORT 2323 +#define MAP_ERRNO(errno) \ + case errno: \ + cmd.err = NERR_##errno; \ + break + +static bool send_response(XDR *xdr, int fd, int err) +{ + struct rpc_header_res cmd; + int ret; + + switch (err) { + MAP_ERRNO(ENOENT); + MAP_ERRNO(EEXIST); + case 0: + cmd.err = NERR_SUCCESS; + break; + default: + fprintf(stderr, "%s cannot map errno %d (%s) to NERR_*\n", + __func__, err, strerror(err)); + cmd.err = NERR_UNKNOWN_ERROR; + break; + } + + xdr_destroy(xdr); + xdrfd_create(xdr, fd, XDR_ENCODE); + + ret = xdr_rpc_header_res(xdr, &cmd); + + return ret ? true : false; +} + +static bool process_command(int fd) +{ + struct rpc_header_req cmd; + bool ok = false; + XDR xdr; + + xdrfd_create(&xdr, fd, XDR_DECODE); + + if (!xdr_rpc_header_req(&xdr, &cmd)) + goto err; + + printf("got opcode %u\n", cmd.opcode); + + switch (cmd.opcode) { + case NRPC_NOP: + ok = true; + break; + default: + send_response(&xdr, fd, ENOTSUP); + break; + } + +err: + xdr_destroy(&xdr); + + return ok; +} + static void process_connection(int fd, void *arg) { printf("%s: fd = %d, arg = %p\n", __func__, fd, arg); + while (process_command(fd)) + ; + close(fd); }