diff options
author | Nathan Straz <nstraz@redhat.com> | 2013-09-19 15:06:55 -0400 |
---|---|---|
committer | Nathan Straz <nstraz@redhat.com> | 2013-09-19 15:06:55 -0400 |
commit | 9a5d808f7143d16bc5d7800271cfa78f666de111 (patch) | |
tree | e6fc955818c6198ca6fe968e40b0c0c60ab1a77c | |
parent | 471105fc6138af9dcd6c0a409c0b4937ea6cac6d (diff) | |
download | qarsh-9a5d808f7143d16bc5d7800271cfa78f666de111.tar.gz qarsh-9a5d808f7143d16bc5d7800271cfa78f666de111.tar.xz qarsh-9a5d808f7143d16bc5d7800271cfa78f666de111.zip |
Reduce size of some fields sent on the wire
We don't need 32bits for packet type or remote fd.
Keeping the field small also helps with reading traces.
-rw-r--r-- | qarsh_packet.c | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/qarsh_packet.c b/qarsh_packet.c index 24f4661..2ca3f13 100644 --- a/qarsh_packet.c +++ b/qarsh_packet.c @@ -204,6 +204,20 @@ qp_packet_type(enum qa_packet_type t) */ char * +fetch_uint8(char *buf, int *buflen, int *out) +{ + uint8_t i; + if (*buflen < sizeof i) { + lprintf(0, "Not enough data to unpack a uint8_t, %d\n", *buflen); + return buf; + } + memcpy(&i, buf, sizeof i); + *out = i; + *buflen -= sizeof i; + return buf + sizeof i; +} + +char * fetch_int(char *buf, int *buflen, int *out) { int i; @@ -338,7 +352,7 @@ parse_qp_rstat(char *buf, int *buflen, struct qa_packet *qp) void parse_qp_data(char *buf, int *buflen, struct qa_packet *qp) { - buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_remfd)); + buf = fetch_uint8(buf, buflen, (int *)&(qp->qp_data.qp_remfd)); buf = fetch_off_t(buf, buflen, &(qp->qp_data.qp_offset)); buf = fetch_int(buf, buflen, (int *)&(qp->qp_data.qp_count)); if (qp->qp_data.qp_count > *buflen) { @@ -355,7 +369,7 @@ parse_qp_data(char *buf, int *buflen, struct qa_packet *qp) void parse_qp_data_allow(char *buf, int *buflen, struct qa_packet *qp) { - buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_remfd)); + buf = fetch_uint8(buf, buflen, (int *)&(qp->qp_dallow.qp_remfd)); buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_count)); } @@ -369,7 +383,7 @@ parse_packet(char *buf, int buflen) memset(qp, 0, sizeof *qp); buf = fetch_int(buf, &buflen, &(qp->qp_seq)); - buf = fetch_int(buf, &buflen, (int *)&(qp->qp_type)); + buf = fetch_uint8(buf, &buflen, (int *)&(qp->qp_type)); if (qa_pi[qp->qp_type].pi_parse) qa_pi[qp->qp_type].pi_parse(buf, &buflen, qp); @@ -387,6 +401,14 @@ parse_packet(char *buf, int buflen) * */ static char * +store_uint8(char *buf, int i) +{ + uint8_t a = i; + memcpy(buf, &a, sizeof a); + return buf + sizeof a; +} + +static char * store_int(char *buf, int i) { i = htobe32(i); @@ -504,7 +526,7 @@ store_qp_rstat(char *buf, struct qa_packet *qp) char * store_qp_data(char *buf, struct qa_packet *qp) { - buf = store_int(buf, qp->qp_data.qp_remfd); + buf = store_uint8(buf, qp->qp_data.qp_remfd); buf = store_off_t(buf, qp->qp_data.qp_offset); buf = store_void(buf, qp->qp_data.qp_count, qp->qp_data.qp_blob); return buf; @@ -513,7 +535,7 @@ store_qp_data(char *buf, struct qa_packet *qp) char * store_qp_data_allow(char *buf, struct qa_packet *qp) { - buf = store_int(buf, qp->qp_dallow.qp_remfd); + buf = store_uint8(buf, qp->qp_dallow.qp_remfd); buf = store_int(buf, qp->qp_dallow.qp_count); return buf; } @@ -528,7 +550,7 @@ qptostr(struct qa_packet *qp, char *qpstr, int maxsize) cp = qpstr; cp = store_int(cp, qp->qp_seq); - cp = store_int(cp, qp->qp_type); + cp = store_uint8(cp, qp->qp_type); if (qa_pi[qp->qp_type].pi_store) { cp = qa_pi[qp->qp_type].pi_store(cp, qp); |