Commit fbb45a08 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Accumulate data read on a local socket.

parent ed2165ba
...@@ -53,10 +53,18 @@ int ...@@ -53,10 +53,18 @@ int
local_read(struct local_socket *s) local_read(struct local_socket *s)
{ {
int rc; int rc;
char buf[500];
/* Ignore anything that comes in, except for EOF */ if(s->buf == NULL)
rc = read(s->fd, buf, 500); s->buf = malloc(LOCAL_BUFSIZE);
if(s->buf == NULL)
return -1;
if(s->n >= LOCAL_BUFSIZE) {
errno = ENOSPC;
return -1;
}
rc = read(s->fd, s->buf + s->n, LOCAL_BUFSIZE - s->n);
if(rc <= 0) if(rc <= 0)
return rc; return rc;
...@@ -327,6 +335,7 @@ local_socket_create(int fd) ...@@ -327,6 +335,7 @@ local_socket_create(int fd)
if(num_local_sockets >= MAX_LOCAL_SOCKETS) if(num_local_sockets >= MAX_LOCAL_SOCKETS)
return NULL; return NULL;
memset(&local_sockets[num_local_sockets], 0, sizeof(struct local_socket));
local_sockets[num_local_sockets].fd = fd; local_sockets[num_local_sockets].fd = fd;
num_local_sockets++; num_local_sockets++;
...@@ -341,6 +350,7 @@ local_socket_destroy(int i) ...@@ -341,6 +350,7 @@ local_socket_destroy(int i)
return; return;
} }
free(local_sockets[i].buf);
close(local_sockets[i].fd); close(local_sockets[i].fd);
local_sockets[i] = local_sockets[--num_local_sockets]; local_sockets[i] = local_sockets[--num_local_sockets];
} }
......
...@@ -34,8 +34,12 @@ struct xroute; ...@@ -34,8 +34,12 @@ struct xroute;
#define MAX_LOCAL_SOCKETS 4 #define MAX_LOCAL_SOCKETS 4
#endif #endif
#define LOCAL_BUFSIZE 1024
struct local_socket { struct local_socket {
int fd; int fd;
char *buf;
int n;
}; };
extern int local_server_socket; extern int local_server_socket;
......
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