add size of message when forwarding (so the remote end can
skip unknown messages safely)
This commit is contained in:
@@ -150,15 +150,18 @@ again:
|
|||||||
void forward(void *_forwarder, char *buf, int size)
|
void forward(void *_forwarder, char *buf, int size)
|
||||||
{
|
{
|
||||||
forward_data *f = _forwarder;
|
forward_data *f = _forwarder;
|
||||||
|
int32_t ssize = size;
|
||||||
databuf *new;
|
databuf *new;
|
||||||
|
|
||||||
new = malloc(sizeof(*new)); if (new == NULL) abort();
|
new = malloc(sizeof(*new)); if (new == NULL) abort();
|
||||||
|
|
||||||
if (pthread_mutex_lock(&f->datalock)) abort();
|
if (pthread_mutex_lock(&f->datalock)) abort();
|
||||||
|
|
||||||
new->d = malloc(size); if (new->d == NULL) abort();
|
new->d = malloc(size + 4); if (new->d == NULL) abort();
|
||||||
memcpy(new->d, buf, size);
|
/* put the size of the message at the head */
|
||||||
new->l = size;
|
memcpy(new->d, &ssize, 4);
|
||||||
|
memcpy(new->d+4, buf, size);
|
||||||
|
new->l = size+4;
|
||||||
new->next = NULL;
|
new->next = NULL;
|
||||||
if (f->head == NULL) f->head = new;
|
if (f->head == NULL) f->head = new;
|
||||||
if (f->tail != NULL) f->tail->next = new;
|
if (f->tail != NULL) f->tail->next = new;
|
||||||
|
|||||||
@@ -91,7 +91,9 @@ void get_message(int s)
|
|||||||
printf("["x"]["y"] %s", str); \
|
printf("["x"]["y"] %s", str); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
int32_t size;
|
||||||
int m;
|
int m;
|
||||||
|
if (GET(s, &size, 4) != 4) abort();
|
||||||
if (GET(s, &m, sizeof(int)) != sizeof(int)) abort();
|
if (GET(s, &m, sizeof(int)) != sizeof(int)) abort();
|
||||||
switch (m) {
|
switch (m) {
|
||||||
case T_first: {
|
case T_first: {
|
||||||
|
|||||||
Reference in New Issue
Block a user