Commit 4b68033b authored by Cedric Roux's avatar Cedric Roux

some work for buffer handling

parent 1e20abdd
...@@ -36,10 +36,12 @@ ...@@ -36,10 +36,12 @@
#define T_PUT_buffer(argnum, val) \ #define T_PUT_buffer(argnum, val) \
do { \ do { \
T_buffer T_PUT_var = (val); \ T_buffer T_PUT_buffer_var = (val); \
T_CHECK_SIZE(T_PUT_var.length, argnum); \ T_PUT_int(argnum, T_PUT_buffer_var.length); \
memcpy(T_LOCAL_buf + T_LOCAL_size, T_PUT_var.addr, T_PUT_var.length); \ T_CHECK_SIZE(T_PUT_buffer_var.length, argnum); \
T_LOCAL_size += T_PUT_var.length; \ memcpy(T_LOCAL_buf + T_LOCAL_size, T_PUT_buffer_var.addr, \
T_PUT_buffer_var.length); \
T_LOCAL_size += T_PUT_buffer_var.length; \
} while (0) } while (0)
#define T_PUT_string(argnum, val) \ #define T_PUT_string(argnum, val) \
...@@ -117,7 +119,7 @@ extern T_cache_t *T_cache; ...@@ -117,7 +119,7 @@ extern T_cache_t *T_cache;
T_send(T_LOCAL_buf, T_LOCAL_size) T_send(T_LOCAL_buf, T_LOCAL_size)
#define T_CHECK_SIZE(len, argnum) \ #define T_CHECK_SIZE(len, argnum) \
if (T_LOCAL_size + len > T_BUFFER_MAX) { \ if (T_LOCAL_size + (len) > T_BUFFER_MAX) { \
printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \ printf("%s:%d:%s: cannot put argument %d in T macro, not enough space" \
", consider increasing T_BUFFER_MAX (%d)\n", \ ", consider increasing T_BUFFER_MAX (%d)\n", \
__FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \ __FILE__, __LINE__, __FUNCTION__, argnum, T_BUFFER_MAX); \
......
...@@ -138,3 +138,4 @@ ID = LEGACY_CLI_DEBUG ...@@ -138,3 +138,4 @@ ID = LEGACY_CLI_DEBUG
ID = LEGACY_CLI_TRACE ID = LEGACY_CLI_TRACE
ID = first ID = first
ID = buf_test
...@@ -10,8 +10,10 @@ int main(void) ...@@ -10,8 +10,10 @@ int main(void)
T_connect_to_tracer("127.0.0.1", 2020); T_connect_to_tracer("127.0.0.1", 2020);
printf("after connect\n"); printf("after connect\n");
while (1) { while (1) {
T(T_first, T_PRINTF("hello world %s!\n", "yo")); char *buf = "hello world %s!\n";
//usleep(1); //T(T_first, T_PRINTF("hello world %s!\n", "yo"));
T(T_buf_test, T_BUFFER("hello world %s!\n", strlen(buf)+1));
usleep(1);
} }
while (1) pause(); while (1) pause();
......
...@@ -73,7 +73,7 @@ void get_string(int s, char *out) ...@@ -73,7 +73,7 @@ void get_string(int s, char *out)
void get_message(int s) void get_message(int s)
{ {
#define S(x, y) do { \ #define S(x, y) do { \
char str[1024]; \ char str[T_BUFFER_MAX]; \
get_string(s, str); \ get_string(s, str); \
printf("["x"]["y"] %s", str); \ printf("["x"]["y"] %s", str); \
} while (0) } while (0)
...@@ -85,7 +85,7 @@ void get_message(int s) ...@@ -85,7 +85,7 @@ void get_message(int s)
if (GET(s, &m, sizeof(int)) != sizeof(int)) abort(); if (GET(s, &m, sizeof(int)) != sizeof(int)) abort();
switch (m) { switch (m) {
case T_first: { case T_first: {
char str[1024]; char str[T_BUFFER_MAX];
get_string(s, str); get_string(s, str);
printf("%s", str); printf("%s", str);
break; break;
...@@ -195,6 +195,15 @@ void get_message(int s) ...@@ -195,6 +195,15 @@ void get_message(int s)
case T_LEGACY_CLI_WARNING: S("CLI", "WARNING"); break; case T_LEGACY_CLI_WARNING: S("CLI", "WARNING"); break;
case T_LEGACY_CLI_DEBUG: S("CLI", "DEBUG"); break; case T_LEGACY_CLI_DEBUG: S("CLI", "DEBUG"); break;
case T_LEGACY_CLI_TRACE: S("CLI", "TRACE"); break; case T_LEGACY_CLI_TRACE: S("CLI", "TRACE"); break;
case T_buf_test: {
unsigned char buf[T_BUFFER_MAX];
int size;
GET(s, &size, sizeof(int));
GET(s, buf, size);
printf("got buffer size %d %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
size, buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],buf[8],buf[9],buf[10],buf[11],buf[12],buf[13],buf[14],buf[15]);
break;
}
default: printf("unkown message type %d\n", m); abort(); default: printf("unkown message type %d\n", m); abort();
} }
......
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