summaryrefslogtreecommitdiff
path: root/ecp/test/init_vconn.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/test/init_vconn.c')
-rw-r--r--ecp/test/init_vconn.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/ecp/test/init_vconn.c b/ecp/test/init_vconn.c
index 88b6fa0..b690bec 100644
--- a/ecp/test/init_vconn.c
+++ b/ecp/test/init_vconn.c
@@ -2,50 +2,59 @@
#include <unistd.h>
#include <stdio.h>
-#include <core.h>
-#include <vconn/vconn.h>
+#include <ecp/core.h>
+#include <ecp/vconn/vconn.h>
-void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
+static void handle_err(ECPConnection *conn, unsigned char mtype, int err) {
printf("ERR: CTYPE:0x%x MTYPE:0x%x ERR:%d\n", conn->type, mtype, err);
}
-static ECPConnection *conn_alloc(ECPSocket *sock, unsigned char type) {
- ECPConnection *conn;
- int rv;
+static ECPConnection *conn_new(ECPSocket *sock, unsigned char type) {
+ ECPConnection *conn = NULL;
switch (type) {
- case ECP_CTYPE_VCONN:
- conn = malloc(sizeof(ECPVConn));
- if (conn) rv = ecp_vconn_create_inb((ECPVConn *)conn, sock);
+ case ECP_CTYPE_VCONN: {
+ ECPVConnInb *_conn;
+
+ _conn = malloc(sizeof(ECPVConnInb));
+ if (_conn) {
+ ecp_vconn_init_inb(_conn, sock);
+ conn = &_conn->b;
+ }
break;
+ }
- case ECP_CTYPE_VLINK:
+ case ECP_CTYPE_VLINK: {
conn = malloc(sizeof(ECPConnection));
- if (conn) rv = ecp_vlink_create_inb(conn, sock);
+ if (conn) ecp_vlink_init(conn, sock);
break;
+ }
- default:
+ default: {
conn = malloc(sizeof(ECPConnection));
- if (conn) rv = ecp_conn_create_inb(conn, sock, type);
+ if (conn) ecp_conn_init(conn, sock, type);
break;
- }
-
- if (conn == NULL) return NULL;
- if (rv) {
- free(conn);
- return NULL;
+ }
}
return conn;
}
static void conn_free(ECPConnection *conn) {
- free(conn);
+ if (ecp_conn_is_gc(conn)) free(conn);
}
-int ecp_init(ECPContext *ctx) {
+int ecp_init(ECPContext *ctx, ECPConnHandler *vconn_handler, ECPConnHandler *vlink_handler) {
int rv;
- rv = ecp_ctx_init(ctx, handle_err, NULL, conn_alloc, conn_free);
- return rv;
+ rv = ecp_ctx_init(ctx, handle_err, conn_new, conn_free);
+ if (rv) return rv;
+
+ rv = ecp_vconn_handler_init(ctx, vconn_handler);
+ if (rv) return rv;
+
+ rv = ecp_vlink_handler_init(ctx, vlink_handler);
+ if (rv) return rv;
+
+ return ECP_OK;
} \ No newline at end of file