From 810dde21ee65653c15606917b19566cfbaaf165e Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Tue, 9 Aug 2022 21:54:45 +0200 Subject: ecp server added --- ecp/test/init_vconn.c | 55 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'ecp/test/init_vconn.c') 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 #include -#include -#include +#include +#include -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 -- cgit v1.2.3