Commit 208ad5db authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Don't send messages on down networks.

parent eb1ac22c
...@@ -534,6 +534,9 @@ ensure_space(struct network *net, int space) ...@@ -534,6 +534,9 @@ ensure_space(struct network *net, int space)
static void static void
start_message(struct network *net, int type, int len) start_message(struct network *net, int type, int len)
{ {
if(!net->up)
return;
if(net->bufsize - net->buffered < len + 2) if(net->bufsize - net->buffered < len + 2)
flushbuf(net); flushbuf(net);
net->sendbuf[net->buffered++] = type; net->sendbuf[net->buffered++] = type;
...@@ -541,7 +544,11 @@ start_message(struct network *net, int type, int len) ...@@ -541,7 +544,11 @@ start_message(struct network *net, int type, int len)
} }
static void static void
end_message(struct network *net, int type, int bytes) { end_message(struct network *net, int type, int bytes)
{
if(!net->up)
return;
assert(net->buffered >= bytes + 2 && assert(net->buffered >= bytes + 2 &&
net->sendbuf[net->buffered - bytes - 2] == type && net->sendbuf[net->buffered - bytes - 2] == type &&
net->sendbuf[net->buffered - bytes - 1] == bytes); net->sendbuf[net->buffered - bytes - 1] == bytes);
...@@ -551,12 +558,18 @@ end_message(struct network *net, int type, int bytes) { ...@@ -551,12 +558,18 @@ end_message(struct network *net, int type, int bytes) {
static void static void
accumulate_byte(struct network *net, unsigned char value) accumulate_byte(struct network *net, unsigned char value)
{ {
if(!net->up)
return;
net->sendbuf[net->buffered++] = value; net->sendbuf[net->buffered++] = value;
} }
static void static void
accumulate_short(struct network *net, unsigned short value) accumulate_short(struct network *net, unsigned short value)
{ {
if(!net->up)
return;
DO_HTONS(net->sendbuf + net->buffered, value); DO_HTONS(net->sendbuf + net->buffered, value);
net->buffered += 2; net->buffered += 2;
} }
...@@ -565,6 +578,9 @@ static void ...@@ -565,6 +578,9 @@ static void
accumulate_bytes(struct network *net, accumulate_bytes(struct network *net,
const unsigned char *value, unsigned len) const unsigned char *value, unsigned len)
{ {
if(!net->up)
return;
memcpy(net->sendbuf + net->buffered, value, len); memcpy(net->sendbuf + net->buffered, value, len);
net->buffered += len; net->buffered += len;
} }
......
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