Commit 5d27f3ab authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Build messages manually, rather than going through the accumulate functions.

parent 64d82779
...@@ -425,45 +425,34 @@ start_message(struct network *net, int bytes) ...@@ -425,45 +425,34 @@ start_message(struct network *net, int bytes)
flushbuf(net); flushbuf(net);
} }
static void
accumulate_byte(struct network *net, unsigned char byte)
{
net->sendbuf[net->buffered] = byte;
net->buffered++;
}
static void
accumulate_short(struct network *net, unsigned short s)
{
*(uint16_t *)(net->sendbuf + net->buffered) = htons(s);
net->buffered += 2;
}
static void
accumulate_data(struct network *net,
const unsigned char *data, unsigned int len)
{
memcpy(net->sendbuf + net->buffered, data, len);
net->buffered += len;
}
static void static void
send_message(struct network *net, send_message(struct network *net,
unsigned char type, unsigned char plen, unsigned char hop_count, unsigned char type, unsigned char plen, unsigned char hop_count,
unsigned short seqno, unsigned short metric, unsigned short seqno, unsigned short metric,
const unsigned char *address) const unsigned char *address)
{ {
unsigned char *buf;
int n;
if(!net->up) if(!net->up)
return; return;
start_message(net, 24); start_message(net, 24);
accumulate_byte(net, type); buf = net->sendbuf;
accumulate_byte(net, plen); n = net->buffered;
accumulate_byte(net, 0);
accumulate_byte(net, hop_count); buf[n++] = type;
accumulate_short(net, seqno); buf[n++] = plen;
accumulate_short(net, metric); buf[n++] = 0;
accumulate_data(net, address, 16); buf[n++] = hop_count;
buf[n++] = (seqno >> 8) & 0xFF;
buf[n++] = seqno & 0xFF;
buf[n++] = (metric >> 8) & 0xFF;
buf[n++] = metric & 0xFF;
memcpy(buf + n, address, 16);
n += 16;
net->buffered = n;
schedule_flush(net); schedule_flush(net);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment