Commit b3889a44 authored by Cedric Roux's avatar Cedric Roux

integration of local tracer into tracee - step 2

The local tracer now waits for the remote tracer to connect,
that's no more the other way around.

All the remote tracers (textlog, enb, vcd) have also been converted.
parent b6854b15
......@@ -16,7 +16,7 @@ void iq_plot_set_sized(void *_plot, short *data, int len, int pp);
void iq_plot_add_iq_point_loop(void *_plot, short i, short q, int pp);
void iq_plot_add_energy_point_loop(void *_plot, int e, int pp);
void *forwarder(char *ip, int port);
void *forwarder(int port);
void forward(void *forwarder, char *buf, int size);
void forward_start_client(void *forwarder, int socket);
......
......@@ -19,6 +19,7 @@ typedef struct {
view *legacy;
} enb_gui;
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021
void usage(void)
......@@ -33,8 +34,10 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n"
" by default, all is off\n"
" -p <port> use given port (default %d)\n"
" -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -debug-gui activate GUI debug logs\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT
);
exit(1);
......@@ -204,6 +207,7 @@ int main(int n, char **v)
extern int volatile gui_logd;
char *database_filename = NULL;
void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT;
char **on_off_name;
int *on_off_action;
......@@ -225,6 +229,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
......@@ -341,7 +346,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port);
s = connect_to(ip, port);
/* send the first message - activate selected traces */
t = 0;
......
......@@ -102,10 +102,11 @@ void forward_start_client(void *_f, int s)
new_thread(forward_s_to_sc, f);
}
void *forwarder(char *ip, int port)
int get_connection(char *addr, int port);
void *forwarder(int port)
{
forward_data *f;
struct sockaddr_in a;
f = malloc(sizeof(*f)); if (f == NULL) abort();
......@@ -119,23 +120,9 @@ void *forwarder(char *ip, int port)
f->memusage = 0;
f->last_warning_memusage = 0;
printf("connecting to remote tracer %s:%d\n", ip, port);
again:
f->s = socket(AF_INET, SOCK_STREAM, 0);
if (f->s == -1) { perror("socket"); exit(1); }
printf("waiting for remote tracer on port %d\n", port);
a.sin_family = AF_INET;
a.sin_port = htons(port);
a.sin_addr.s_addr = inet_addr(ip);
if (connect(f->s, (struct sockaddr *)&a, sizeof(a)) == -1) {
perror("connect");
close(f->s);
printf("trying again in 1s\n");
sleep(1);
goto again;
}
f->s = get_connection("127.0.0.1", port);
printf("connected\n");
......
......@@ -9,8 +9,7 @@
#include <fcntl.h>
#include <pthread.h>
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021
#define DEFAULT_PORT 2021
#include "defs.h"
......@@ -97,11 +96,9 @@ void usage(void)
printf(
"tracer - local side\n"
"options:\n"
" -r <IP address> <port> forwards packets to remote IP:port\n"
" (default %s:%d)\n"
" -nowait don't wait for remote tracer,\n"
" start tracee immediately\n",
DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT
" -p <port> wait for remote tracer on port <port> (default %d)\n"
" -nowait don't wait for remote tracer, start tracee immediately\n",
DEFAULT_PORT
);
exit(1);
}
......@@ -110,30 +107,29 @@ int main(int n, char **v)
{
int s;
int i;
char *remote_ip = DEFAULT_REMOTE_IP;
int remote_port = DEFAULT_REMOTE_PORT;
int port = 2020;
int port = DEFAULT_PORT;
int local_port = 2020;
int dont_wait = 0;
void *f;
for (i = 1; i < n; i++) {
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-r")) { if (i > n-3) usage();
remote_ip = v[++i]; remote_port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-p")) { if (i > n-2) usage();
port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-nowait")) { dont_wait = 1; continue; }
printf("ERROR: unknown option %s\n", v[i]);
usage();
}
init_shm();
s = get_connection("127.0.0.1", port);
s = get_connection("127.0.0.1", local_port);
if (dont_wait) {
char t = 2;
if (write(s, &t, 1) != 1) abort();
}
f = forwarder(remote_ip, remote_port);
f = forwarder(port);
forward_start_client(f, s);
/* read messages */
......
......@@ -13,6 +13,7 @@
#include "event_selector.h"
#include "config.h"
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021
void usage(void)
......@@ -27,10 +28,12 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n"
" by default, all is off\n"
" -p <port> use given port (default %d)\n"
" -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -x GUI output\n"
" -debug-gui activate GUI debug logs\n"
" -no-gui disable GUI entirely\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT
);
exit(1);
......@@ -48,6 +51,7 @@ int main(int n, char **v)
extern int volatile gui_logd;
char *database_filename = NULL;
void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT;
char **on_off_name;
int *on_off_action;
......@@ -72,6 +76,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
......@@ -136,7 +141,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port);
s = connect_to(ip, port);
/* send the first message - activate selected traces */
t = 0;
......
......@@ -125,6 +125,32 @@ int fullread(int fd, void *_buf, int count)
return ret;
}
int connect_to(char *addr, int port)
{
int s;
struct sockaddr_in a;
printf("connecting to %s:%d\n", addr, port);
again:
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1) { perror("socket"); exit(1); }
a.sin_family = AF_INET;
a.sin_port = htons(port);
a.sin_addr.s_addr = inet_addr(addr);
if (connect(s, (struct sockaddr *)&a, sizeof(a)) == -1) {
perror("connect");
close(s);
printf("trying again in 1s\n");
sleep(1);
goto again;
}
return s;
}
/****************************************************************************/
/* buffer */
/****************************************************************************/
......
......@@ -23,6 +23,7 @@ list *list_append(list *l, void *data);
void socket_send(int socket, void *buffer, int size);
int get_connection(char *addr, int port);
int fullread(int fd, void *_buf, int count);
int connect_to(char *addr, int port);
/****************************************************************************/
/* buffer */
......
......@@ -13,6 +13,7 @@
#include "event_selector.h"
#include "config.h"
#define DEFAULT_REMOTE_IP "127.0.0.1"
#define DEFAULT_REMOTE_PORT 2021
void usage(void)
......@@ -27,8 +28,10 @@ void usage(void)
" note: you may pass several -on/-off/-ON/-OFF,\n"
" they will be processed in order\n"
" by default, all is off\n"
" -p <port> use given port (default %d)\n"
" -ip <host> connect to given IP address (default %s)\n"
" -p <port> connect to given port (default %d)\n"
" -debug-gui activate GUI debug logs\n",
DEFAULT_REMOTE_IP,
DEFAULT_REMOTE_PORT
);
exit(1);
......@@ -88,6 +91,7 @@ int main(int n, char **v)
extern int volatile gui_logd;
char *database_filename = NULL;
void *database;
char *ip = DEFAULT_REMOTE_IP;
int port = DEFAULT_REMOTE_PORT;
char **on_off_name;
int *on_off_action;
......@@ -108,6 +112,7 @@ int main(int n, char **v)
if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
if (!strcmp(v[i], "-d"))
{ if (i > n-2) usage(); database_filename = v[++i]; continue; }
if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
if (!strcmp(v[i], "-p"))
{ if (i > n-2) usage(); port = atoi(v[++i]); continue; }
if (!strcmp(v[i], "-on")) { if (i > n-2) usage();
......@@ -147,7 +152,7 @@ int main(int n, char **v)
for (i = 0; i < on_off_n; i++)
on_off(database, on_off_name[i], is_on, on_off_action[i]);
s = get_connection("0.0.0.0", port);
s = connect_to(ip, port);
/* send the first message - activate selected traces */
t = 0;
......
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