forked from enlightenment/efl
add request # tracking. this should detect badness - like forking and using
the connection from the fork (the cserve connection). it won't catch threads... most of the time, but i need something else for that i think. SVN revision: 40869
This commit is contained in:
parent
7c66538545
commit
3528238bbe
|
@ -64,6 +64,7 @@ struct _Server
|
|||
void *data;
|
||||
pid_t pid;
|
||||
int server_id;
|
||||
int req_from, req_to;
|
||||
};
|
||||
|
||||
struct _Client
|
||||
|
@ -78,6 +79,7 @@ struct _Client
|
|||
void (*func) (void *fdata, Client *c);
|
||||
void *data;
|
||||
pid_t pid;
|
||||
int req_from, req_to;
|
||||
};
|
||||
|
||||
struct _Mem
|
||||
|
|
|
@ -85,13 +85,15 @@ server_disconnect(Server *s)
|
|||
static int
|
||||
server_send(Server *s, int opcode, int size, unsigned char *data)
|
||||
{
|
||||
int ints[2];
|
||||
int ints[3];
|
||||
int num;
|
||||
|
||||
pipe_handle(1);
|
||||
ints[0] = size;
|
||||
ints[1] = opcode;
|
||||
num = write(s->fd, ints, (sizeof(int) * 2));
|
||||
s->req_to++;
|
||||
ints[2] = s->req_to;
|
||||
num = write(s->fd, ints, (sizeof(int) * 3));
|
||||
if (num < 0)
|
||||
{
|
||||
pipe_handle(0);
|
||||
|
@ -114,11 +116,11 @@ server_send(Server *s, int opcode, int size, unsigned char *data)
|
|||
static unsigned char *
|
||||
server_read(Server *s, int *opcode, int *size)
|
||||
{
|
||||
int ints[2], num, left;
|
||||
int ints[3], num, left;
|
||||
unsigned char *data;
|
||||
|
||||
num = read(s->fd, ints, sizeof(int) * 2);
|
||||
if (num != (sizeof(int) * 2))
|
||||
num = read(s->fd, ints, sizeof(int) * 3);
|
||||
if (num != (sizeof(int) * 3))
|
||||
{
|
||||
if (cserve) server_disconnect(cserve);
|
||||
cserve = NULL;
|
||||
|
@ -127,6 +129,15 @@ server_read(Server *s, int *opcode, int *size)
|
|||
*size = ints[0];
|
||||
*opcode = ints[1];
|
||||
if ((*size < 0) || (*size > (1024 * 1024))) return NULL;
|
||||
if (ints[2] != (s->req_from + 1))
|
||||
{
|
||||
printf("EEK! sequence number mismatch from serer with pid: %i\n"
|
||||
"---- num %i is not 1 more than %i\n"
|
||||
,
|
||||
s->pid, ints[2], s->req_from);
|
||||
return NULL;
|
||||
}
|
||||
s->req_from++;
|
||||
data = malloc(*size);
|
||||
if (!data) return NULL;
|
||||
num = read(s->fd, data, *size);
|
||||
|
|
|
@ -178,13 +178,15 @@ evas_cserve_client_send(Client *c, int opcode, int size, unsigned char *data)
|
|||
unsigned char *data2;
|
||||
int *ints;
|
||||
|
||||
data2 = malloc(size + (sizeof(int) * 2));
|
||||
data2 = malloc(size + (sizeof(int) * 3));
|
||||
if (!data2) return;
|
||||
ints = (int *)data2;
|
||||
ints[0] = size;
|
||||
ints[1] = opcode;
|
||||
memcpy(data2 + (sizeof(int) * 2), data, size);
|
||||
client_write(c, data2, size + (sizeof(int) * 2));
|
||||
c->req_to++;
|
||||
ints[2] = c->req_to;
|
||||
memcpy(data2 + (sizeof(int) * 3), data, size);
|
||||
client_write(c, data2, size + (sizeof(int) * 3));
|
||||
free(data2);
|
||||
}
|
||||
|
||||
|
@ -211,13 +213,22 @@ server_parse(Server *s, Client *c)
|
|||
ints = (int *)((c->inbuf));
|
||||
if ((ints[0] < 0) || (ints[0] > (1024 * 1024)))
|
||||
return 0;
|
||||
if (c->inbufsize < (ints[0] + (sizeof(int) * 2)))
|
||||
if (c->inbufsize < (ints[0] + (sizeof(int) * 3)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
data = c->inbuf + (sizeof(int) * 2);
|
||||
data = c->inbuf + (sizeof(int) * 3);
|
||||
if (ints[2] != (c->req_from + 1))
|
||||
{
|
||||
printf("EEK! sequence number mismatch from client with pid: %i\n"
|
||||
"---- num %i is not 1 more than %i\n"
|
||||
,
|
||||
c->pid, ints[2], c->req_from);
|
||||
return 0;
|
||||
}
|
||||
c->req_from++;
|
||||
server_message_handle(s, c, ints[1], ints[0], data);
|
||||
c->inbufalloc -= ints[0] + (sizeof(int) * 2);
|
||||
c->inbufalloc -= ints[0] + (sizeof(int) * 3);
|
||||
if (c->inbufalloc == 0)
|
||||
{
|
||||
free(c->inbuf);
|
||||
|
@ -228,12 +239,12 @@ server_parse(Server *s, Client *c)
|
|||
newbuf = malloc(c->inbufalloc);
|
||||
if (!newbuf)
|
||||
{
|
||||
c->inbufalloc += ints[0] + (sizeof(int) * 2);
|
||||
c->inbufalloc += ints[0] + (sizeof(int) * 3);
|
||||
/* fixme - bad situation */
|
||||
return 0;
|
||||
}
|
||||
memcpy(newbuf, c->inbuf + ints[0] + (sizeof(int) * 2), c->inbufalloc);
|
||||
c->inbufsize -= ints[0] + (sizeof(int) * 2);
|
||||
memcpy(newbuf, c->inbuf + ints[0] + (sizeof(int) * 3), c->inbufalloc);
|
||||
c->inbufsize -= ints[0] + (sizeof(int) * 3);
|
||||
free(c->inbuf);
|
||||
c->inbuf = newbuf;
|
||||
return 1;
|
||||
|
|
Loading…
Reference in New Issue