Commit bb051c02 authored by Cedric Roux's avatar Cedric Roux

T_messages.txt is now sent by local_tracer.c

And it's sent at each connection attempt.
Before it was sent only once to the first tracer.
Plus there was a bug (length:(len) should have been length:(send_size)).
parent d47e3074
#include "T.h" #include "T.h"
#include "T_messages.txt.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
...@@ -113,8 +112,6 @@ void T_init(int remote_port, int wait_for_tracer) ...@@ -113,8 +112,6 @@ void T_init(int remote_port, int wait_for_tracer)
int socket_pair[2]; int socket_pair[2];
int s; int s;
int T_shm_fd; int T_shm_fd;
unsigned char *buf;
int len;
int child1, child2; int child1, child2;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair)) if (socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair))
...@@ -153,29 +150,4 @@ void T_init(int remote_port, int wait_for_tracer) ...@@ -153,29 +150,4 @@ void T_init(int remote_port, int wait_for_tracer)
close(T_shm_fd); close(T_shm_fd);
new_thread(T_receive_thread, NULL); new_thread(T_receive_thread, NULL);
/* trace T_message.txt
* Send several messages -1 with content followed by message -2.
* We can't use the T macro directly, events -1 and -2 are special.
*/
buf = T_messages_txt;
len = T_messages_txt_len;
while (len) {
int send_size = len;
if (send_size > T_PAYLOAD_MAXSIZE - sizeof(int))
send_size = T_PAYLOAD_MAXSIZE - sizeof(int);
do {
T_LOCAL_DATA
T_HEADER(T_ID(-1));
T_PUT_buffer(1, ((T_buffer){addr:(buf), length:(len)}));
T_COMMIT();
} while (0);
buf += send_size;
len -= send_size;
}
do {
T_LOCAL_DATA
T_HEADER(T_ID(-2));
T_COMMIT();
} while (0);
} }
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <inttypes.h> #include <inttypes.h>
#include <signal.h> #include <signal.h>
#include "T.h"
#include "T_messages.txt.h"
#include "T_defs.h" #include "T_defs.h"
#include "T_IDs.h" #include "T_IDs.h"
...@@ -85,6 +87,38 @@ static int get_connection(char *addr, int port) ...@@ -85,6 +87,38 @@ static int get_connection(char *addr, int port)
return t; return t;
} }
static void forward(void *_forwarder, char *buf, int size);
void send_T_messages_txt(void *forwarder)
{
char buf[T_BUFFER_MAX];
char *T_LOCAL_buf = buf;
int T_LOCAL_size;
unsigned char *src;
int src_len;
/* trace T_message.txt
* Send several messages -1 with content followed by message -2.
*/
src = T_messages_txt;
src_len = T_messages_txt_len;
while (src_len) {
int send_size = src_len;
if (send_size > T_PAYLOAD_MAXSIZE - sizeof(int))
send_size = T_PAYLOAD_MAXSIZE - sizeof(int);
/* TODO: be careful, we use internal T stuff, to rewrite? */
T_LOCAL_size = 0;
T_HEADER(T_ID(-1));
T_PUT_buffer(1, ((T_buffer){addr:(src), length:(send_size)}));
forward(forwarder, buf, T_LOCAL_size);
src += send_size;
src_len -= send_size;
}
T_LOCAL_size = 0;
T_HEADER(T_ID(-2));
forward(forwarder, buf, T_LOCAL_size);
}
/****************************************************************************/ /****************************************************************************/
/* forward functions */ /* forward functions */
/****************************************************************************/ /****************************************************************************/
...@@ -213,6 +247,7 @@ dead: ...@@ -213,6 +247,7 @@ dead:
close(f->socket_remote); close(f->socket_remote);
f->socket_remote = get_connection("0.0.0.0", f->remote_port); f->socket_remote = get_connection("0.0.0.0", f->remote_port);
send_T_messages_txt(f);
goto again; goto again;
return NULL; return NULL;
...@@ -237,6 +272,7 @@ static void *forwarder(int port, int s) ...@@ -237,6 +272,7 @@ static void *forwarder(int port, int s)
f->remote_port = port; f->remote_port = port;
f->socket_remote = get_connection("0.0.0.0", port); f->socket_remote = get_connection("0.0.0.0", port);
send_T_messages_txt(f);
new_thread(data_sender, f); new_thread(data_sender, f);
new_thread(forward_remote_messages, f); new_thread(forward_remote_messages, f);
......
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