[PATCH 1/3] cld: Create cldc_call_opts_get_data API for GET

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create the cldc_call_opts_get_data API. This allows users of the async CLD api
to access the GET buffer returned from CLD without playing with parts of the
cld_call_opts marked 'private, lib-owned.'

Signed-off-by: Colin McCabe <cmccabe@xxxxxxxxxxxxxx>
---
 include/cldc.h         |    2 ++
 lib/cldc.c             |    7 +++++++
 test/load-file-event.c |    7 +++++--
 tools/cldcli.c         |   23 ++++++++++++++++-------
 4 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/include/cldc.h b/include/cldc.h
index 0f4242e..afcba71 100644
--- a/include/cldc.h
+++ b/include/cldc.h
@@ -209,6 +209,8 @@ extern int cldc_dirent_next(struct cld_dirent_cur *dc);
 extern void cldc_dirent_cur_init(struct cld_dirent_cur *dc, const void *buf, size_t buflen);
 extern void cldc_dirent_cur_fini(struct cld_dirent_cur *dc);
 extern char *cldc_dirent_name(struct cld_dirent_cur *dc);
+extern void cldc_call_opts_get_data(const struct cldc_call_opts *copts,
+				const char **data, size_t *data_len);
 
 /* cldc-udp */
 extern void cldc_udp_free(struct cldc_udp *udp);
diff --git a/lib/cldc.c b/lib/cldc.c
index 50f102f..56070e2 100644
--- a/lib/cldc.c
+++ b/lib/cldc.c
@@ -1308,6 +1308,13 @@ char *cldc_dirent_name(struct cld_dirent_cur *dc)
 	return s;
 }
 
+void cldc_call_opts_get_data(const struct cldc_call_opts *copts,
+				const char **data, size_t *data_len)
+{
+	*data = copts->u.get.buf;
+	*data_len = copts->u.get.size;
+}
+
 /*
  * For extra safety, call cldc_init after g_thread_init, if present.
  * Currently we just call srand(), but since we use GLib, we may need
diff --git a/test/load-file-event.c b/test/load-file-event.c
index 94e0421..477cad8 100644
--- a/test/load-file-event.c
+++ b/test/load-file-event.c
@@ -147,18 +147,21 @@ static int read_1_cb(struct cldc_call_opts *coptarg, enum cle_err_codes errc)
 	struct run *rp = coptarg->private;
 	struct cldc_call_opts copts;
 	int rc;
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		fprintf(stderr, "first-get failed: %d\n", errc);
 		exit(1);
 	}
 
-	if (coptarg->u.get.size != TESTLEN) {
+	cldc_call_opts_get_data(coptarg, &data, &data_len);
+	if (data_len != TESTLEN) {
 		fprintf(stderr, "Bad CLD file length %d\n", coptarg->u.get.size);
 		exit(1);
 	}
 
-	if (memcmp(coptarg->u.get.buf, TESTSTR, TESTLEN)) {
+	if (memcmp(data, TESTSTR, TESTLEN)) {
 		fprintf(stderr, "Bad CLD file content\n");
 		exit(1);
 	}
diff --git a/tools/cldcli.c b/tools/cldcli.c
index c4735d0..567a5c5 100644
--- a/tools/cldcli.c
+++ b/tools/cldcli.c
@@ -217,6 +217,8 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 	struct cldc_call_opts copts = { NULL, };
 	struct cld_dirent_cur dc;
 	int rc, i;
+	const char *data;
+	size_t data_len;
 	bool first = true;
 
 	if (errc != CLE_OK) {
@@ -224,8 +226,9 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
 	}
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
 
-	rc = cldc_dirent_count(copts_in->u.get.buf, copts_in->u.get.size);
+	rc = cldc_dirent_count(data, data_len);
 	if (rc < 0) {
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
@@ -236,7 +239,7 @@ static int cb_ls_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 
 	write_from_thread(&cresp, sizeof(cresp));
 
-	cldc_dirent_cur_init(&dc, copts_in->u.get.buf, copts_in->u.get.size);
+	cldc_dirent_cur_init(&dc, data, data_len);
 
 	for (i = 0; i < rc; i++) {
 		struct ls_rec lsr;
@@ -294,6 +297,8 @@ static int cb_cat_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 {
 	struct cresp cresp = { .tcode = TC_FAILED, };
 	struct cldc_call_opts copts = { NULL, };
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		errc_msg(&cresp, errc);
@@ -301,11 +306,13 @@ static int cb_cat_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 		return 0;
 	}
 
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
+
 	cresp.tcode = TC_OK;
-	cresp.u.file_len = copts_in->u.get.size;
+	cresp.u.file_len = data_len;
 
 	write_from_thread(&cresp, sizeof(cresp));
-	write_from_thread(copts_in->u.get.buf, copts_in->u.get.size);
+	write_from_thread(data, data_len);
 
 	/* FIXME: race; should wait until close succeeds/fails before
 	 * returning any data.  'fh' may still be in use, otherwise.
@@ -338,18 +345,20 @@ static int cb_cp_cf_2(struct cldc_call_opts *copts_in, enum cle_err_codes errc)
 {
 	struct cresp cresp = { .tcode = TC_FAILED, };
 	struct cldc_call_opts copts = { NULL, };
+	const char *data;
+	size_t data_len;
 
 	if (errc != CLE_OK) {
 		errc_msg(&cresp, errc);
 		write_from_thread(&cresp, sizeof(cresp));
 		return 0;
 	}
-
+	cldc_call_opts_get_data(copts_in, &data, &data_len);
 	cresp.tcode = TC_OK;
-	cresp.u.file_len = copts_in->u.get.size;
+	cresp.u.file_len = data_len;
 
 	write_from_thread(&cresp, sizeof(cresp));
-	write_from_thread(copts_in->u.get.buf, copts_in->u.get.size);
+	write_from_thread(data, data_len);
 
 	/* FIXME: race; should wait until close succeeds/fails before
 	 * returning any data.  'fh' may still be in use, otherwise.
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux