[Pdbg] [PATCH v4 1/4] libcronus: Pass expected data size to cronus_request
Amitay Isaacs
amitay at ozlabs.org
Thu Nov 7 13:32:46 AEDT 2019
This is in preparation of sbefifo transport, which can send large
amount of data.
Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
libcronus/cfam.c | 4 ++--
libcronus/libcronus_private.h | 2 +-
libcronus/request.c | 17 +++++++++++++----
libcronus/scom.c | 4 ++--
4 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/libcronus/cfam.c b/libcronus/cfam.c
index 8ad3973..ab93e51 100644
--- a/libcronus/cfam.c
+++ b/libcronus/cfam.c
@@ -65,7 +65,7 @@ int cronus_getcfam(struct cronus_context *cctx,
cbuf_write_uint32(&cbuf_request, sizeof(devstr));
cbuf_write(&cbuf_request, (uint8_t *)devstr, sizeof(devstr));
- ret = cronus_request(cctx, key, &cbuf_request, &cbuf_reply);
+ ret = cronus_request(cctx, key, 0, &cbuf_request, &cbuf_reply);
if (ret) {
fprintf(stderr, "Failed to talk to server\n");
return ret;
@@ -148,7 +148,7 @@ int cronus_putcfam(struct cronus_context *cctx,
cbuf_write_uint32(&cbuf_request, 8 * sizeof(uint32_t)); // length in bits
cbuf_write_uint32(&cbuf_request, value);
- ret = cronus_request(cctx, key, &cbuf_request, &cbuf_reply);
+ ret = cronus_request(cctx, key, 0, &cbuf_request, &cbuf_reply);
if (ret) {
fprintf(stderr, "Failed to talk to server\n");
return ret;
diff --git a/libcronus/libcronus_private.h b/libcronus/libcronus_private.h
index 9a6c720..70f559d 100644
--- a/libcronus/libcronus_private.h
+++ b/libcronus/libcronus_private.h
@@ -43,7 +43,7 @@ struct cronus_reply {
uint32_t cronus_key(struct cronus_context *cctx);
int cronus_request(struct cronus_context *cctx,
- uint32_t key,
+ uint32_t key, uint32_t out_len,
struct cronus_buffer *request,
struct cronus_buffer *reply);
int cronus_parse_reply(uint32_t key,
diff --git a/libcronus/request.c b/libcronus/request.c
index 60f928a..612453f 100644
--- a/libcronus/request.c
+++ b/libcronus/request.c
@@ -26,12 +26,12 @@
#include "libcronus_private.h"
int cronus_request(struct cronus_context *cctx,
- uint32_t key,
+ uint32_t key, uint32_t out_len,
struct cronus_buffer *request,
struct cronus_buffer *reply)
{
- uint8_t buf[1024], *ptr;
- size_t len = 0;
+ uint8_t *buf, *ptr;
+ size_t len = 0, buflen;
ssize_t n;
int ret;
@@ -41,25 +41,34 @@ int cronus_request(struct cronus_context *cctx,
ptr = cbuf_finish(request, &len);
assert(len > 0);
+ buflen = 1024 + out_len;
+ buf = malloc(buflen);
+ if (!buf)
+ return ENOMEM;
+
n = write(cctx->fd, ptr, len);
if (n == -1) {
+ free(buf);
ret = errno;
perror("write");
return ret;
}
if (n != len) {
+ free(buf);
fprintf(stderr, "Short write (%zu of %zu) to server\n", n, len);
return EIO;
}
- n = read(cctx->fd, buf, sizeof(buf));
+ n = read(cctx->fd, buf, buflen);
if (n == -1) {
+ free(buf);
ret = errno;
perror("read");
return ret;
}
ret = cbuf_new_from_buf(reply, buf, n);
+ free(buf);
if (ret)
return ret;
diff --git a/libcronus/scom.c b/libcronus/scom.c
index 5679ae5..71991c2 100644
--- a/libcronus/scom.c
+++ b/libcronus/scom.c
@@ -66,7 +66,7 @@ int cronus_getscom(struct cronus_context *cctx,
cbuf_write_uint32(&cbuf_request, sizeof(devstr));
cbuf_write(&cbuf_request, (uint8_t *)devstr, sizeof(devstr));
- ret = cronus_request(cctx, key, &cbuf_request, &cbuf_reply);
+ ret = cronus_request(cctx, key, 0, &cbuf_request, &cbuf_reply);
if (ret) {
fprintf(stderr, "Failed to talk to server\n");
return ret;
@@ -150,7 +150,7 @@ int cronus_putscom(struct cronus_context *cctx,
cbuf_write_uint32(&cbuf_request, 8 * sizeof(uint64_t)); // length in bits
cbuf_write_uint64(&cbuf_request, value);
- ret = cronus_request(cctx, key, &cbuf_request, &cbuf_reply);
+ ret = cronus_request(cctx, key, 0, &cbuf_request, &cbuf_reply);
if (ret) {
fprintf(stderr, "Failed to talk to server\n");
return ret;
--
2.21.0
More information about the Pdbg
mailing list