Commit 52cf61de authored by Cedric Roux's avatar Cedric Roux

T tracer: don't depend on T_BUFFER_MAX anymore in the tracers

Whenever the value T_BUFFER_MAX changes, the tracers had to
be recompiled. The only reason why it was needed is because we
used some fixed size buffers to read events. This commit removes
this restriction.

Also, with the basic simulator, this value T_BUFFER_MAX now comes
with an #ifdef which would have required some special hackish-level
tricks in the tracers, which is not good.

Let's just allocate memory when needed.
parent 6cb04bb4
......@@ -12,7 +12,6 @@
#include "gui/gui.h"
#include "filter/filter.h"
#include "utils.h"
#include "../T_defs.h"
#include "event_selector.h"
#include "openair_logo.h"
#include "config.h"
......@@ -875,6 +874,8 @@ int main(int n, char **v)
if (pthread_mutex_init(&enb_data.lock, NULL)) abort();
setup_event_selector(g, database, is_on, is_on_changed, &enb_data);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
restart:
clear_remote_config();
enb_data.socket = connect_to(ip, port);
......@@ -884,9 +885,8 @@ restart:
/* read messages */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(enb_data.socket, v, database);
e = get_event(enb_data.socket, &ebuf, database);
if (e.type == -1) goto restart;
if (pthread_mutex_lock(&enb_data.lock)) abort();
handle_event(h, e);
......
......@@ -6,7 +6,7 @@
#include <stdlib.h>
#include <string.h>
event get_event(int socket, char *event_buffer, void *database)
event get_event(int socket, OBUF *event_buffer, void *database)
{
#ifdef T_SEND_TIME
struct timespec t;
......@@ -29,17 +29,23 @@ again:
#endif
if (fullread(socket, &type, sizeof(int)) == -1) goto read_error;
length -= sizeof(int);
if (fullread(socket, event_buffer, length) == -1) goto read_error;
if (event_buffer->omaxsize < length) {
event_buffer->omaxsize = (length + 65535) & ~65535;
event_buffer->obuf = realloc(event_buffer->obuf, event_buffer->omaxsize);
if (event_buffer->obuf == NULL) { printf("out of memory\n"); exit(1); }
}
if (fullread(socket, event_buffer->obuf, length) == -1) goto read_error;
event_buffer->osize = length;
if (type == -1) append_received_config_chunk(event_buffer, length);
if (type == -1) append_received_config_chunk(event_buffer->obuf, length);
if (type == -2) verify_config();
if (type == -1 || type == -2) goto again;
#ifdef T_SEND_TIME
return new_event(t, type, length, event_buffer, database);
return new_event(t, type, length, event_buffer->obuf, database);
#else
return new_event(type, length, event_buffer, database);
return new_event(type, length, event_buffer->obuf, database);
#endif
read_error:
......
#ifndef _EVENT_H_
#define _EVENT_H_
#include "utils.h"
#include "../T_defs.h"
#ifdef T_SEND_TIME
#include <time.h>
......@@ -37,7 +38,7 @@ typedef struct {
int ecount;
} event;
event get_event(int s, char *v, void *d);
event get_event(int s, OBUF *v, void *d);
#ifdef T_SEND_TIME
event new_event(struct timespec sending_time, int type,
......
......@@ -99,10 +99,11 @@ int main(int n, char **v)
found = 0;
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(fd, v, database);
e = get_event(fd, &ebuf, database);
if (e.type == -1) break;
if (e.type != input_event_id) continue;
for (i = 0; i < filter_count; i++)
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "../T_defs.h"
void usage(void)
......@@ -35,14 +36,22 @@ int main(int n, char **v)
in = fopen(input_filename, "r");
if (in == NULL) { perror(input_filename); abort(); }
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
while (1) {
int type;
int32_t length;
char v[T_BUFFER_MAX];
char *v;
int vpos = 0;
/* read event from file */
if (fread(&length, 4, 1, in) != 1) break;
if (ebuf.omaxsize < length) {
ebuf.omaxsize = (length + 65535) & ~65535;
ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize);
if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); }
}
v = ebuf.obuf;
memcpy(v+vpos, &length, 4);
vpos += 4;
#ifdef T_SEND_TIME
......
......@@ -104,11 +104,12 @@ err:
fd = open(file, O_RDONLY);
if (fd == -1) { perror(file); exit(1); }
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* get wanted frame/subframe */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(fd, v, database);
e = get_event(fd, &ebuf, database);
if (e.type == -1) break;
if (e.type != input_event_id) continue;
if (verbose)
......
......@@ -100,10 +100,12 @@ err:
int last_frame = -1;
int last_subframe = -1;
int subframe_written = 0;
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(fd, v, database);
e = get_event(fd, &ebuf, database);
if (e.type == -1) break;
if (e.type != output_event_id) continue;
if (verbose)
......
......@@ -73,17 +73,22 @@ int main(int n, char **v)
socket_send(socket, is_on, number_of_events * sizeof(int)) == -1)
abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
char dump[10][T_BUFFER_MAX];
event dump_ev[10];
FILE *z = fopen("/tmp/dd", "w"); if (z == NULL) abort();
while (1) {
char v[T_BUFFER_MAX];
char *v;
event e;
e = get_event(socket, v, database);
e = get_event(socket, &ebuf, database);
v = ebuf.obuf;
if (e.type == -1) break;
if (e.type == ev_input) {
int sf = e.e[2].i;
memcpy(dump[sf], v, T_BUFFER_MAX);
if (ebuf.osize > T_BUFFER_MAX)
{ printf("event size too big\n"); exit(1); }
memcpy(dump[sf], ebuf.obuf, ebuf.osize);
dump_ev[sf] = e;
printf("input %d/%d\n", e.e[1].i, sf);
if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort();
......
......@@ -84,11 +84,12 @@ int main(int n, char **v)
socket_send(socket, is_on, number_of_events * sizeof(int)) == -1)
abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
while (1) {
char v[T_BUFFER_MAX];
event e;
int on_off;
e = get_event(socket, v, database);
e = get_event(socket, &ebuf, database);
if (e.type == -1) break;
if (e.type != ev_fun)
{ printf("unhandled event %d\n", e.type); continue; }
......
......@@ -246,11 +246,12 @@ int main(int n, char **v)
new_thread(receiver, &d);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* read messages */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(in, v, database);
e = get_event(in, &ebuf, database);
if (e.type == -1) break;
if (!(e.type == ul_id || e.type == dl_id)) continue;
handle_event(h, e);
......
......@@ -123,14 +123,22 @@ int main(int n, char **v)
if (signal(SIGINT, force_stop) == SIG_ERR) abort();
if (signal(SIGTSTP, force_stop) == SIG_ERR) abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* read messages */
while (run) {
int type;
int32_t length;
char v[T_BUFFER_MAX];
char *v;
int vpos = 0;
if (fullread(socket, &length, 4) == -1) goto read_error;
if (ebuf.omaxsize < length) {
ebuf.omaxsize = (length + 65535) & ~65535;
ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize);
if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); }
}
v = ebuf.obuf;
memcpy(v+vpos, &length, 4);
vpos += 4;
#ifdef T_SEND_TIME
......
......@@ -136,14 +136,22 @@ int main(int n, char **v)
new_thread(get_message_thread, &socket);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
while (1) {
int type;
int32_t length;
char v[T_BUFFER_MAX];
char *v;
int vpos = 0;
/* read event from file */
if (fread(&length, 4, 1, in) != 1) break;
if (ebuf.omaxsize < length) {
ebuf.omaxsize = (length + 65535) & ~65535;
ebuf.obuf = realloc(ebuf.obuf, ebuf.omaxsize);
if (ebuf.obuf == NULL) { printf("out of memory\n"); exit(1); }
}
v = ebuf.obuf;
memcpy(v+vpos, &length, 4);
vpos += 4;
#ifdef T_SEND_TIME
......
......@@ -10,7 +10,6 @@
#include "view/view.h"
#include "gui/gui.h"
#include "utils.h"
#include "../T_defs.h"
#include "event_selector.h"
#include "config.h"
......@@ -182,11 +181,12 @@ int main(int n, char **v)
/* send the first message - activate selected traces */
is_on_changed(&textlog_data);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* read messages */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(textlog_data.socket, v, database);
e = get_event(textlog_data.socket, &ebuf, database);
if (e.type == -1) abort();
handle_event(h, e);
}
......
......@@ -287,11 +287,12 @@ int main(int n, char **v)
if (signal(SIGINT, force_stop) == SIG_ERR) abort();
if (signal(SIGTSTP, force_stop) == SIG_ERR) abort();
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* read messages */
while (run) {
char v[T_BUFFER_MAX];
event e;
e = get_event(socket, v, database);
e = get_event(socket, &ebuf, database);
if (e.type == -1) { printf("disconnected? let's quit gently\n"); break; }
handle_event(h, e);
}
......
......@@ -12,7 +12,6 @@
#include "gui/gui.h"
#include "filter/filter.h"
#include "utils.h"
#include "../T_defs.h"
#include "event_selector.h"
#include "openair_logo.h"
#include "config.h"
......@@ -854,6 +853,8 @@ int main(int n, char **v)
if (pthread_mutex_init(&ue_data.lock, NULL)) abort();
setup_event_selector(g, database, is_on, is_on_changed, &ue_data);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
restart:
clear_remote_config();
ue_data.socket = connect_to(ip, port);
......@@ -863,9 +864,8 @@ restart:
/* read messages */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(ue_data.socket, v, database);
e = get_event(ue_data.socket, &ebuf, database);
if (e.type == -1) goto restart;
if (pthread_mutex_lock(&ue_data.lock)) abort();
handle_event(h, e);
......
......@@ -10,7 +10,6 @@
#include "view/view.h"
#include "gui/gui.h"
#include "utils.h"
#include "../T_defs.h"
#include "event_selector.h"
#include "config.h"
......@@ -188,11 +187,12 @@ int main(int n, char **v)
/* send the first message - activate selected traces */
is_on_changed(&vcd_data);
OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL };
/* read messages */
while (1) {
char v[T_BUFFER_MAX];
event e;
e = get_event(vcd_data.socket, v, database);
e = get_event(vcd_data.socket, &ebuf, 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