# HG changeset patch # User Holly Sipek # Date 1445193645 14400 # Node ID 5b4d4496c9c658bff8a0a2d3cc5e42e1b2868380 # Parent 127b60f41bbff2c2cc38ef2a873e445e36f9ea5d client: make each new connection stateful. This closes #31. Signed-off-by: Holly Sipek Signed-off-by: Josef 'Jeff' Sipek diff -r 127b60f41bbf -r 5b4d4496c9c6 src/client/cmds.c --- a/src/client/cmds.c Sun Oct 18 14:09:32 2015 -0400 +++ b/src/client/cmds.c Sun Oct 18 14:40:45 2015 -0400 @@ -1,5 +1,6 @@ /* * Copyright (c) 2015 Josef 'Jeff' Sipek + * Copyright (c) 2015 Holly Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -110,7 +111,7 @@ return true; } -bool process_connection(int fd) +bool process_connection(struct fsconn *conn) { struct rpc_header_req hdr; union cmd cmd; @@ -121,7 +122,7 @@ memset(&hdr, 0, sizeof(struct rpc_header_req)); memset(&cmd, 0, sizeof(union cmd)); - xdrfd_create(&xdr, fd, XDR_DECODE); + xdrfd_create(&xdr, conn->fd, XDR_DECODE); if (!xdr_rpc_header_req(&xdr, &hdr)) goto out; @@ -153,7 +154,7 @@ ret = def->handler(&cmd); /* send back the response header */ - ok = send_response(&xdr, fd, ret); + ok = send_response(&xdr, conn->fd, ret); /* send back the response payload */ if (ok && def->res) @@ -162,7 +163,7 @@ goto out; } - send_response(&xdr, fd, ENOTSUP); + send_response(&xdr, conn->fd, ENOTSUP); out: xdr_destroy(&xdr); diff -r 127b60f41bbf -r 5b4d4496c9c6 src/client/cmds.h --- a/src/client/cmds.h Sun Oct 18 14:09:32 2015 -0400 +++ b/src/client/cmds.h Sun Oct 18 14:40:45 2015 -0400 @@ -1,5 +1,6 @@ /* * Copyright (c) 2015 Josef 'Jeff' Sipek + * Copyright (c) 2015 Holly Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +25,7 @@ #define __NOMAD_CLIENT_CMDS_H #include +#include union cmd { /* create */ @@ -58,7 +60,12 @@ } stat; }; -extern bool process_connection(int fd); +struct fsconn { + int fd; + struct objstore *vg; +}; + +extern bool process_connection(struct fsconn *conn); /* RPC handlers */ extern int cmd_create(union cmd *cmd); diff -r 127b60f41bbf -r 5b4d4496c9c6 src/client/main.c --- a/src/client/main.c Sun Oct 18 14:09:32 2015 -0400 +++ b/src/client/main.c Sun Oct 18 14:40:45 2015 -0400 @@ -1,5 +1,6 @@ /* * Copyright (c) 2015 Josef 'Jeff' Sipek + * Copyright (c) 2015 Holly Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -35,9 +36,13 @@ static void connection_acceptor(int fd, void *arg) { + struct fsconn conn; + + conn.fd = fd; + conn.vg = NULL; printf("%s: fd = %d, arg = %p\n", __func__, fd, arg); - while (process_connection(fd)) + while (process_connection(&conn)) ; }