Commit 83350a80 authored by Cedric Roux's avatar Cedric Roux
Browse files

reading a socket does not abort anymore

fullread has been changed, so get_event too, and the callers also
for the moment the callers crash, enb.c will be a bit more clever,
the others to see...
parent 9338f06e
......@@ -386,6 +386,7 @@ int main(int n, char **v)
char v[T_BUFFER_MAX];
event e;
e = get_event(enb_data.socket, v, database);
if (e.type == -1) abort();
handle_event(h, e);
}
......
......@@ -22,14 +22,14 @@ event get_event(int socket, char *event_buffer, void *database)
*/
again:
fullread(socket, &length, 4);
if (fullread(socket, &length, 4) == -1) goto read_error;
#ifdef T_SEND_TIME
fullread(socket, &t, sizeof(struct timespec));
if (fullread(socket, &t, sizeof(struct timespec)) == -1) goto read_error;
length -= sizeof(struct timespec);
#endif
fullread(socket, &type, sizeof(int));
if (fullread(socket, &type, sizeof(int)) == -1) goto read_error;
length -= sizeof(int);
fullread(socket, event_buffer, length);
if (fullread(socket, event_buffer, length) == -1) goto read_error;
if (type == -1) append_received_config_chunk(event_buffer, length);
if (type == -2) verify_config();
......@@ -41,6 +41,9 @@ again:
#else
return new_event(type, length, event_buffer, database);
#endif
read_error:
return (event){type: -1};
}
#ifdef T_SEND_TIME
......
......@@ -182,6 +182,7 @@ int main(int n, char **v)
char v[T_BUFFER_MAX];
event e;
e = get_event(textlog_data.socket, v, database);
if (e.type == -1) abort();
handle_event(h, e);
}
......
......@@ -118,7 +118,7 @@ int fullread(int fd, void *_buf, int count)
int l;
while (count) {
l = read(fd, buf, count);
if (l <= 0) { printf("read socket problem\n"); abort(); }
if (l <= 0) return -1;
count -= l;
buf += l;
ret += l;
......
......@@ -23,6 +23,7 @@ list *list_append(list *l, void *data);
/* socket_send: return 0 if okay, -1 on error */
int socket_send(int socket, void *buffer, int size);
int get_connection(char *addr, int port);
/* fullread: return length read if okay (that is: 'count'), -1 on error */
int fullread(int fd, void *_buf, int count);
int connect_to(char *addr, int port);
......
......@@ -192,6 +192,7 @@ int main(int n, char **v)
char v[T_BUFFER_MAX];
event e;
e = get_event(vcd_data.socket, v, database);
if (e.type == -1) abort();
handle_event(h, e);
}
......
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