summaryrefslogtreecommitdiff
path: root/code/test/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'code/test/client.c')
-rw-r--r--code/test/client.c58
1 files changed, 16 insertions, 42 deletions
diff --git a/code/test/client.c b/code/test/client.c
index b8a2ba5..e6c8208 100644
--- a/code/test/client.c
+++ b/code/test/client.c
@@ -2,14 +2,13 @@
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
-#include <sys/time.h>
#include "core.h"
#include "util.h"
-ECPContext ctx_c;
-ECPSocket sock_c;
-ECPConnHandler handler_c;
+ECPContext ctx;
+ECPSocket sock;
+ECPConnHandler handler;
ECPNode node;
ECPConnection conn;
@@ -17,11 +16,7 @@ ECPConnection conn;
#define CTYPE_TEST 0
#define MTYPE_MSG 8
-int counter = 0;
-uint64_t t_start = 0;
-uint64_t t_end = 0;
-
-ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
+ssize_t handle_open(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
uint32_t seq = 0;
ecp_conn_handle_open(conn, sq, t, p, s, b);
@@ -36,32 +31,11 @@ ssize_t handle_open_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsign
strcpy((char *)buf, msg);
ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000);
- struct timeval tv;
- gettimeofday(&tv, NULL);
- t_start = tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
-
return s;
}
-ssize_t handle_msg_c(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
- counter++;
- // printf("MSG C:%s size:%ld\n", p, s);
- char *msg = "PERA JE CAR!";
- unsigned char buf[1000];
-
- strcpy((char *)buf, msg);
- ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000);
-
- if (counter % 100 == 0) {
- struct timeval tv;
- uint64_t t_time;
-
- gettimeofday(&tv, NULL);
- t_end = tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
- t_time = t_end - t_start;
- printf("T:%f\n", (float)t_time/1000000);
- t_start = t_end;
- }
+ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned char *p, ssize_t s, ECP2Buffer *b) {
+ printf("MSG C:%s size:%ld\n", p, s);
return s;
}
@@ -76,27 +50,27 @@ int main(int argc, char *argv[]) {
if (argc != 2) usage(argv[0]);
- rv = ecp_init(&ctx_c);
+ rv = ecp_init(&ctx);
printf("ecp_init RV:%d\n", rv);
- rv = ecp_conn_handler_init(&handler_c);
- handler_c.msg[ECP_MTYPE_OPEN] = handle_open_c;
- handler_c.msg[MTYPE_MSG] = handle_msg_c;
- ctx_c.handler[CTYPE_TEST] = &handler_c;
+ rv = ecp_conn_handler_init(&handler);
+ handler.msg[ECP_MTYPE_OPEN] = handle_open;
+ handler.msg[MTYPE_MSG] = handle_msg;
+ ctx.handler[CTYPE_TEST] = &handler;
- rv = ecp_sock_create(&sock_c, &ctx_c, NULL);
+ rv = ecp_sock_create(&sock, &ctx, NULL);
printf("ecp_sock_create RV:%d\n", rv);
- rv = ecp_sock_open(&sock_c, NULL);
+ rv = ecp_sock_open(&sock, NULL);
printf("ecp_sock_open RV:%d\n", rv);
- rv = ecp_start_receiver(&sock_c);
+ rv = ecp_start_receiver(&sock);
printf("ecp_start_receiver RV:%d\n", rv);
- rv = ecp_util_node_load(&ctx_c, &node, argv[1]);
+ rv = ecp_util_node_load(&ctx, &node, argv[1]);
printf("ecp_util_node_load RV:%d\n", rv);
- rv = ecp_conn_create(&conn, &sock_c, CTYPE_TEST);
+ rv = ecp_conn_create(&conn, &sock, CTYPE_TEST);
printf("ecp_conn_create RV:%d\n", rv);
rv = ecp_conn_open(&conn, &node);