summaryrefslogtreecommitdiff
path: root/code/test/vid/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'code/test/vid/server.c')
-rw-r--r--code/test/vid/server.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/code/test/vid/server.c b/code/test/vid/server.c
new file mode 100644
index 0000000..08653f1
--- /dev/null
+++ b/code/test/vid/server.c
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include "server.h"
+#include "util.h"
+
+static ECPContext ctx_s;
+static ECPSocket sock_s;
+static ECPDHKey key_perma_s;
+static ECPConnHandler handler_s;
+
+static ECPConnection *conn;
+static int is_open = 0;
+
+#define CTYPE_TEST 0
+#define MTYPE_MSG 8
+
+static ssize_t handle_open(ECPConnection *c, ecp_seq_t sq, unsigned char t, unsigned char *m, ssize_t sz) {
+ ssize_t rv = ecp_conn_handle_open(c, sq, t, m, sz);
+ if (rv < 0) return rv;
+
+ conn = c;
+ is_open = 1;
+
+ return rv;
+}
+
+ssize_t send_frame(unsigned char *buffer, size_t size, ecp_pts_t pts) {
+ return ecp_send(conn, MTYPE_MSG, buffer, size);
+}
+
+int conn_is_open(void) {
+ return is_open;
+}
+
+int init_server(char *address, char *key) {
+ int rv;
+
+ rv = ecp_init(&ctx_s);
+ printf("ecp_init RV:%d\n", rv);
+
+ if (!rv) rv = ecp_conn_handler_init(&handler_s);
+ if (!rv) {
+ handler_s.msg[ECP_MTYPE_OPEN] = handle_open;
+ ctx_s.handler[CTYPE_TEST] = &handler_s;
+ }
+
+ if (!rv) rv = ecp_util_key_load(&ctx_s, &key_perma_s, key);
+ printf("ecp_util_key_load RV:%d\n", rv);
+
+ if (!rv) rv = ecp_sock_create(&sock_s, &ctx_s, &key_perma_s);
+ printf("ecp_sock_create RV:%d\n", rv);
+
+ if (!rv) rv = ecp_sock_open(&sock_s, address);
+ printf("ecp_sock_open RV:%d\n", rv);
+
+ if (!rv) rv = ecp_start_receiver(&sock_s);
+ printf("ecp_start_receiver RV:%d\n", rv);
+
+ return rv;
+}