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...
This commit is contained in:
Cedric Roux
2016-06-05 17:39:06 +02:00
parent 9338f06e90
commit 83350a807f
6 changed files with 12 additions and 5 deletions
+1
View File
@@ -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);
}
+7 -4
View File
@@ -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
+1
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+1
View File
@@ -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);
+1
View File
@@ -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);
}