changeset 150:5b4d4496c9c6

client: make each new connection stateful. This closes #31. Signed-off-by: Holly Sipek <holly.sipek@gmail.com> Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Holly Sipek <holly.sipek@gmail.com>
date Sun, 18 Oct 2015 14:40:45 -0400
parents 127b60f41bbf
children 4557170a0481
files src/client/cmds.c src/client/cmds.h src/client/main.c
diffstat 3 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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 <jeffpc@josefsipek.net>
+ * 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);
--- 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 <jeffpc@josefsipek.net>
+ * 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 <nomad/rpc_fs.h>
+#include <nomad/objstore.h>
 
 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);
--- 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 <jeffpc@josefsipek.net>
+ * 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))
 		;
 }