Portability: Don't pack struct

main
cel 5 years ago
parent cfb1d40d73
commit 52ec6488b4

@ -73,11 +73,6 @@ enum pkt_flags {
pkt_flags_stream = 8, pkt_flags_stream = 8,
}; };
struct pkt_header {
uint32_t len;
int32_t req;
} __attribute__((packed));
enum muxrpc_type { enum muxrpc_type {
muxrpc_type_async, muxrpc_type_async,
muxrpc_type_source, muxrpc_type_source,
@ -689,9 +684,11 @@ static enum stream_state bs_write_in_1(struct boxs *bs, int fd) {
static void ps_write(struct boxs *bs, const char *data, size_t len, enum pkt_type type, int req_id, bool stream, bool end) { static void ps_write(struct boxs *bs, const char *data, size_t len, enum pkt_type type, int req_id, bool stream, bool end) {
size_t out_len = 9 + len; size_t out_len = 9 + len;
unsigned char out_buf[out_len]; unsigned char out_buf[out_len];
struct pkt_header header = {htonl(len), htonl(req_id)}; uint32_t len_n = htonl(len);
int32_t req_n = htonl(req_id);
out_buf[0] = (stream << 3) | (end << 2) | (type & 3); out_buf[0] = (stream << 3) | (end << 2) | (type & 3);
memcpy(out_buf+1, &header, 8); memcpy(out_buf+1, &len_n, 4);
memcpy(out_buf+5, &req_n, 4);
memcpy(out_buf+9, data, len); memcpy(out_buf+9, data, len);
bs_write(bs, out_buf, out_len); bs_write(bs, out_buf, out_len);
} }
@ -704,11 +701,13 @@ static void ps_goodbye(struct boxs *bs) {
static int ps_read_header(struct boxs *bs, size_t *len, int *req_id, enum pkt_flags *flags) { static int ps_read_header(struct boxs *bs, size_t *len, int *req_id, enum pkt_flags *flags) {
char buf[9]; char buf[9];
struct pkt_header header; uint32_t len_n;
int32_t req_n;
if (bs_read(bs, buf, sizeof(buf)) < 0) return -1; if (bs_read(bs, buf, sizeof(buf)) < 0) return -1;
memcpy(&header, buf+1, 8); memcpy(&len_n, buf+1, 4);
if (len) *len = ntohl(header.len); memcpy(&req_n, buf+5, 4);
if (req_id) *req_id = ntohl(header.req); if (len) *len = ntohl(len_n);
if (req_id) *req_id = ntohl(req_n);
if (flags) *flags = buf[0]; if (flags) *flags = buf[0];
return 0; return 0;
} }

Loading…
Cancel
Save