Using struct <type> instead of typedefs.
authorPeter Somogyi <psomogyi@gamax.hu>
Wed, 13 Dec 2006 10:02:49 +0000 (11:02 +0100)
committerPeter Somogyi <psomogyi@gamax.hu>
Wed, 13 Dec 2006 10:02:49 +0000 (11:02 +0100)
ib/ibwrapper.c
ib/ibwrapper.h
ib/ibwrapper_internal.h

index 2f53cf1a04ec4cf9618af9a9e93c6f0f2cc2bcf7..268469d9e1943d0f7ecc8fe29deb43702a3023bb 100644 (file)
@@ -45,13 +45,13 @@ static char ibw_lasterr[IBW_LASTERR_BUFSIZE];
 static void ibw_event_handler_verbs(struct event_context *ev,
        struct fd_event *fde, uint16_t flags, void *private_data);
 
-static int ibw_init_memory(ibw_conn *conn)
+static int ibw_init_memory(struct ibw_conn *conn)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
 
        int     i;
-       ibw_wr  *p;
+       struct ibw_wr   *p;
 
        pconn->buf = memalign(pctx->page_size, pctx->max_msg_size);
        if (!pconn->buf) {
@@ -65,10 +65,10 @@ static int ibw_init_memory(ibw_conn *conn)
                return -1;
        }
 
-       pconn->wr_index = talloc_size(pconn, pctx->qsize * sizeof(ibw_wr *));
+       pconn->wr_index = talloc_size(pconn, pctx->qsize * sizeof(struct ibw_wr *));
 
        for(i=0; i<pctx->qsize; i++) {
-               p = pconn->wr_index[i] = talloc_zero(pconn, ibw_wr);
+               p = pconn->wr_index[i] = talloc_zero(pconn, struct ibw_wr);
                p->msg = pconn->buf + (i * pctx->max_msg_size);
                p->wr_id = i;
 
@@ -80,7 +80,7 @@ static int ibw_init_memory(ibw_conn *conn)
 
 static int ibw_ctx_priv_destruct(void *ptr)
 {
-       ibw_ctx *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
+       struct ibw_ctx *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
        assert(pctx!=NULL);
 
        if (pctx->pd) {
@@ -106,7 +106,7 @@ static int ibw_ctx_priv_destruct(void *ptr)
 
 static int ibw_ctx_destruct(void *ptr)
 {
-       ibw_ctx *ctx = talloc_get_type(ptr, ibw_ctx);
+       struct ibw_ctx *ctx = talloc_get_type(ptr, struct ibw_ctx);
        assert(ctx!=NULL);
 
        return 0;
@@ -114,7 +114,7 @@ static int ibw_ctx_destruct(void *ptr)
 
 static int ibw_conn_priv_destruct(void *ptr)
 {
-       ibw_conn *pconn = talloc_get_type(ptr, ibw_conn_priv);
+       struct ibw_conn *pconn = talloc_get_type(ptr, struct ibw_conn_priv);
        assert(pconn!=NULL);
 
        /* free memory regions */
@@ -156,8 +156,8 @@ static int ibw_conn_priv_destruct(void *ptr)
 
 static int ibw_conn_destruct(void *ptr)
 {
-       ibw_conn *conn = talloc_get_type(ptr, ibw_conn);
-       ibw_ctx *ctx;
+       struct ibw_conn *conn = talloc_get_type(ptr, struct ibw_conn);
+       struct ibw_ctx  *ctx;
 
        assert(conn!=NULL);
        ctx = ibw_conn->ctx;
@@ -167,18 +167,18 @@ static int ibw_conn_destruct(void *ptr)
        return 0;
 }
 
-static ibw_conn *ibw_conn_new(ibw_ctx *ctx)
+static struct ibw_conn *ibw_conn_new(struct ibw_ctx *ctx)
 {
-       ibw_conn *conn;
-       ibw_conn_priv *pconn;
+       struct ibw_conn *conn;
+       struct ibw_conn_priv *pconn;
 
-       conn = talloc_zero(ctx, ibw_conn);
+       conn = talloc_zero(ctx, struct ibw_conn);
        assert(conn!=NULL);
-       talloc_set_destructor(conn, ibw_conn_destruct);
+       talloc_set_destructor(conn, struct ibw_conn_destruct);
 
-       pconn = talloc_zero(ctx, ibw_conn_priv);
+       pconn = talloc_zero(ctx, struct ibw_conn_priv);
        assert(pconn!=NULL);
-       talloc_set_destructor(pconn, ibw_conn_priv_destruct);
+       talloc_set_destructor(pconn, struct ibw_conn_priv_destruct);
 
        conn->ctx = ctx;
 
@@ -187,10 +187,10 @@ static ibw_conn *ibw_conn_new(ibw_ctx *ctx)
        return conn;
 }
 
-static int ibw_setup_cq_qp(ibw_conn *conn)
+static int ibw_setup_cq_qp(struct ibw_conn *conn)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
        struct ibv_qp_init_attr init_attr;
        int rc;
 
@@ -243,10 +243,10 @@ static int ibw_setup_cq_qp(ibw_conn *conn)
        return rc;
 }
 
-static int ibw_refill_cq_recv(ibw_conn *conn)
+static int ibw_refill_cq_recv(struct ibw_conn *conn)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
        int     i, rc;
        struct ibv_sge list = {
                .addr   = (uintptr_t) NULL,
@@ -259,7 +259,7 @@ static int ibw_refill_cq_recv(ibw_conn *conn)
                .num_sge    = 1,
        };
        struct ibv_recv_wr *bad_wr;
-       ibw_wr  *p = pconn->wr_list_avail;
+       struct ibw_wr   *p = pconn->wr_list_avail;
 
        if (p==NULL) {
                sprintf(ibw_last_err, "out of wr_list_avail");
@@ -281,10 +281,10 @@ static int ibw_refill_cq_recv(ibw_conn *conn)
        return 0;
 }
 
-static int ibw_fill_cq(ibw_conn *conn)
+static int ibw_fill_cq(struct ibw_conn *conn)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
        int     i, rc;
        struct ibv_sge list = {
                .addr   = (uintptr_t) NULL,
@@ -297,7 +297,7 @@ static int ibw_fill_cq(ibw_conn *conn)
                .num_sge    = 1,
        };
        struct ibv_recv_wr *bad_wr;
-       ibw_wr  *p;
+       struct ibw_wr   *p;
 
        for(i = pctx->opts.max_recv_wr; i!=0; i--) {
                p = pconn->wr_list_avail;
@@ -322,7 +322,7 @@ static int ibw_fill_cq(ibw_conn *conn)
        return 0;
 }
 
-static int ibw_manage_connect(ibw_conn *conn, struct rdma_cm_id *cma_id)
+static int ibw_manage_connect(struct ibw_conn *conn, struct rdma_cm_id *cma_id)
 {
        struct rdma_conn_param conn_param;
        int     rc;
@@ -348,10 +348,10 @@ static void ibw_event_handler_cm(struct event_context *ev,
        struct fd_event *fde, uint16_t flags, void *private_data)
 {
        int     rc;
-       ibw_ctx *ctx = talloc_get_type(private_data, ibw_ctx);
-       ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
-       ibw_conn *conn = NULL;
-       ibw_conn_priv *pconn = NULL;
+       struct ibw_ctx  *ctx = talloc_get_type(private_data, struct ibw_ctx);
+       struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn *conn = NULL;
+       struct ibw_conn_priv *pconn = NULL;
        struct rdma_cm_id *cma_id = NULL;
        struct rdma_cm_event *event = NULL;
 
@@ -371,8 +371,6 @@ static void ibw_event_handler_cm(struct event_context *ev,
        switch (event->event) {
        case RDMA_CM_EVENT_ADDR_RESOLVED:
                /* continuing from ibw_connect ... */
-               assert(pctx->state==IWINT_INIT);
-               pctx->state = IWINT_ADDR_RESOLVED;
                rc = rdma_resolve_route(cma_id, 2000);
                if (rc) {
                        ctx->state = ERROR;
@@ -384,11 +382,8 @@ static void ibw_event_handler_cm(struct event_context *ev,
 
        case RDMA_CM_EVENT_ROUTE_RESOLVED:
                /* after RDMA_CM_EVENT_ADDR_RESOLVED: */
-               assert(pctx->state==IWINT_ADDR_RESOLVED);
-               pctx->state = IWINT_ROUTE_RESOLVED;
                assert(cma_id->context!=NULL);
-               conn = talloc_get_type(cma_id->context, ibw_conn);
-               pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+               conn = talloc_get_type(cma_id->context, struct ibw_conn);
 
                rc = ibw_manage_connect(conn, cma_id);
                if (rc)
@@ -399,7 +394,7 @@ static void ibw_event_handler_cm(struct event_context *ev,
        case RDMA_CM_EVENT_CONNECT_REQUEST:
                ctx->state = IBWS_CONNECT_REQUEST;
                conn = ibw_conn_new(ctx);
-               pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+               pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
                pconn->cm_id = cma_id; /* !!! event will be freed but id not */
                cma_id->context = (void *)conn;
                DEBUG(10, "pconn->cm_id %p\n", pconn->cm_id);
@@ -426,9 +421,8 @@ static void ibw_event_handler_cm(struct event_context *ev,
        case RDMA_CM_EVENT_ESTABLISHED:
                /* expected after ibw_accept and ibw_connect[not directly] */
                DEBUG(0, "ESTABLISHED (conn: %u)\n", cma_id->context);
-               conn = talloc_get_type(cma_id->context, ibw_conn);
+               conn = talloc_get_type(cma_id->context, struct ibw_conn);
                assert(conn!=NULL); /* important assumption */
-               pconn = talloc_get_type(conn->internal, ibw_conn_priv);
 
                /* client conn is up */
                conn->state = IBWC_CONNECTED;
@@ -448,7 +442,7 @@ static void ibw_event_handler_cm(struct event_context *ev,
        case RDMA_CM_EVENT_DISCONNECTED:
                if (cma_id!=ctx->cm_id) {
                        DEBUG(0, "client DISCONNECT event\n");
-                       conn = talloc_get_type(cma_id->context, ibw_conn);
+                       conn = talloc_get_type(cma_id->context, struct ibw_conn);
                        conn->state = IBWC_DISCONNECTED;
                        pctx->connstate_func(NULL, conn);
 
@@ -483,7 +477,7 @@ static void ibw_event_handler_cm(struct event_context *ev,
 error:
        DEBUG(0, "cm event handler: %s", ibw_lasterr);
        if (cma_id!=ctx->cm_id) {
-               conn = talloc_get_type(cma_id->context, ibw_conn);
+               conn = talloc_get_type(cma_id->context, struct ibw_conn);
                if (conn)
                        conn->state = IBWC_ERROR;
                pctx->connstate_func(NULL, conn);
@@ -496,9 +490,9 @@ error:
 static void ibw_event_handler_verbs(struct event_context *ev,
        struct fd_event *fde, uint16_t flags, void *private_data)
 {
-       ibw_ctx *conn = talloc_get_type(private_data, ibw_conn);
-       ibw_ctx_priv *pconn = talloc_get_type(conn->internal, ibw_ctx_priv);
-       ibw_ctx *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
+       struct ibw_ctx  *conn = talloc_get_type(private_data, struct ibw_conn);
+       struct ibw_ctx_priv *pconn = talloc_get_type(conn->internal, struct ibw_ctx_priv);
+       struct ibw_ctx  *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
 
        struct ibv_wc wc;
        int rc;
@@ -517,7 +511,7 @@ static void ibw_event_handler_verbs(struct event_context *ev,
        switch(wc.opcode) {
        case IBV_WC_SEND:
                {
-                       ibw_wr  *p;
+                       struct ibw_wr   *p;
        
                        DEBUG(10, "send completion\n");
                        assert(pconn->qp->qp_num==wc.qp_num);
@@ -538,7 +532,7 @@ static void ibw_event_handler_verbs(struct event_context *ev,
 
        case IBV_WC_RECV:
                {
-                       ibw_wr  *p;
+                       struct ibw_wr   *p;
        
                        assert(pconn->qp->qp_num==wc.qp_num);
                        assert(wc.wr_id < pctx->qsize);
@@ -568,7 +562,7 @@ error:
        pctx->connstate_func(NULL, conn);
 }
 
-static int ibw_process_init_attrs(ibw_initattr *attr, int nattr, ibw_opts *opts)
+static int ibw_process_init_attrs(struct ibw_initattr *attr, int nattr, struct ibw_opts *opts)
 {
        int     i, mtu;
        char *name, *value;
@@ -593,15 +587,15 @@ static int ibw_process_init_attrs(ibw_initattr *attr, int nattr, ibw_opts *opts)
        return 0;
 }
 
-ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
+struct ibw_ctx *ibw_init(struct ibw_initattr *attr, int nattr,
        void *ctx_userdata,
        ibw_connstate_fn_t ibw_connstate,
        ibw_receive_fn_t ibw_receive,
        event_content *ectx,
        int max_msg_size)
 {
-       ibw_ctx *ctx = talloc_zero(NULL, ibw_ctx);
-       ibw_ctx_priv *pctx;
+       struct ibw_ctx *ctx = talloc_zero(NULL, struct ibw_ctx);
+       struct ibw_ctx_priv *pctx;
        int     rc;
 
        /* initialize basic data structures */
@@ -612,7 +606,7 @@ ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
        talloc_set_destructor(ctx, ibw_ctx_destruct);
        ctx->userdata = userdata;
 
-       pctx = talloc_zero(ctx, ibw_ctx_priv);
+       pctx = talloc_zero(ctx, struct ibw_ctx_priv);
        talloc_set_destructor(pctx, ibw_ctx_priv_destruct);
        ctx->internal = (void *)pctx;
        assert(pctx!=NULL);
@@ -667,10 +661,10 @@ cleanup:
        return NULL;
 }
 
-int ibw_stop(ibw_ctx *ctx)
+int ibw_stop(struct ibw_ctx *ctx)
 {
-       ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
-       ibw_conn *p;
+       struct ibw_ctx_priv *pctx = (struct ibw_ctx_priv *)ctx->internal;
+       struct ibw_conn *p;
 
        for(p=ctx->conn_list; p!=NULL; p=p->next) {
                if (ctx->state==IBWC_ERROR || ctx->state==IBWC_CONNECTED) {
@@ -682,9 +676,9 @@ int ibw_stop(ibw_ctx *ctx)
        return 0;
 }
 
-int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr)
+int ibw_bind(struct ibw_ctx *ctx, struct sockaddr_in *my_addr)
 {
-       ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
+       struct ibw_ctx_priv *pctx = (struct ibw_ctx_priv *)ctx->internal;
        int     rc;
 
        rc = rdma_bind_addr(pctx->cm_id, (struct sockaddr *) my_addr);
@@ -698,9 +692,9 @@ int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr)
        return 0;
 }
 
-int ibw_listen(ibw_ctx *ctx, int backlog)
+int ibw_listen(struct ibw_ctx *ctx, int backlog)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
        int     rc;
 
        DEBUG_LOG("rdma_listen...\n");
@@ -714,10 +708,10 @@ int ibw_listen(ibw_ctx *ctx, int backlog)
        return 0;
 }
 
-int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata)
+int ibw_accept(struct ibw_ctx *ctx, struct ibw_conn *conn, void *conn_userdata)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
        struct rdma_conn_param  conn_param;
 
        conn->conn_userdata = conn_userdata;
@@ -739,15 +733,15 @@ int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata)
        return 0;
 }
 
-int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
+int ibw_connect(struct ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
 {
-       ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
-       ibw_conn *conn = NULL;
+       struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+       struct ibw_conn *conn = NULL;
        int     rc;
 
        conn = ibw_conn_new(ctx);
        conn->conn_userdata = conn_userdata;
-       pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+       pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
 
        rc = rdma_create_id(pctx->cm_channel, &pconn->cm_id, conn, RDMA_PS_TCP);
        if (rc) {
@@ -770,11 +764,11 @@ int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata
        return 0;
 }
 
-void ibw_disconnect(ibw_conn *conn)
+void ibw_disconnect(struct ibw_conn *conn)
 {
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
-       ibw_ctx *ctx = conn->ctx;
-       ibw_ctx_priv *pctx = talloc_get_type(ctx->internal);
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
+       struct ibw_ctx *ctx = conn->ctx;
+       struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal);
 
        rdma_disconnect(pctx->cm_id);
 
@@ -783,11 +777,11 @@ void ibw_disconnect(ibw_conn *conn)
        return 0;
 }
 
-int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key)
+int ibw_alloc_send_buf(struct ibw_conn *conn, void **buf, void **key)
 {
-       ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
-       ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_wr *p = pctx->wr_list_avail;
+       struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
+       struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_wr *p = pctx->wr_list_avail;
 
        if (p==NULL) {
                sprintf(ibw_last_err, "insufficient wr chunks\n");
@@ -803,10 +797,10 @@ int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key)
        return pctx->buf;
 }
 
-int ibw_send(ibw_conn *conn, void *buf, void *key, int n)
+int ibw_send(struct ibw_conn *conn, void *buf, void *key, int n)
 {
-       ibw_ctx_priv pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
-       ibw_wr *p = talloc_get_type(key, ibw_wr);
+       struct ibw_ctx_priv pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+       struct ibw_wr *p = talloc_get_type(key, struct ibw_wr);
        struct ibv_sge list = {
                .addr   = (uintptr_t) p->msg,
                .length = n,
index 7afe76dc3fac7cc4921726b86ba41cfb8c17ba43..da80705696687d8933caf65ec65c621e073f912f 100644 (file)
  */
 
 /* Server communication state */
-typedef enum {
+enum ibw_state_ctx {
        IBWS_INIT = 0, /* ctx start - after ibw_init */
        IBWS_READY, /* after ibw_bind & ibw_listen */
        IBWS_CONNECT_REQUEST, /* after [IBWS_READY + incoming request] */
                /* => [(ibw_accept)IBWS_READY | (ibw_disconnect)STOPPED | ERROR] */
        IBWS_STOPPED, /* normal stop <= ibw_disconnect+(IBWS_READY | IBWS_CONNECT_REQUEST) */
        IBWS_ERROR /* abnormal state; ibw_stop must be called after this */
-} ibw_state_ctx;
+};
 
 /* Connection state */
-typedef struct _ibw_ctx {
+typedef struct ibw_ctx {
        void *ctx_userdata; /* see ibw_init */
 
-       ibw_state_ctx state;
+       struct ibw_state_ctx state;
        void *internal;
 
-       ibw_conn *conn_list; /* 1st elem of double linked list */
-} ibw_ctx;
+       struct ibw_conn *conn_list; /* 1st elem of double linked list */
+};
 
-typedef enum {
+enum ibw_state_conn {
        IBWC_INIT = 0, /* conn start - internal state */
        IBWC_CONNECTED, /* after ibw_accept or ibw_connect */
        IBWC_DISCONNECTED, /* after ibw_disconnect */
        IBWC_ERROR
-} ibw_state_conn;
+};
 
-typedef struct _ibw_conn {
-       ibw_ctx *ctx;
-       ibw_state_conn state;
+struct ibw_conn {
+       struct ibw_ctx *ctx;
+       struct ibw_state_conn state;
 
        void *conn_userdata; /* see ibw_connect and ibw_accept */
        void *internal;
 
-       ibw_conn *prev, next;
-} ibw_conn;
+       struct ibw_conn *prev, next;
+};
 
 /*
  * (name, value) pair for array param of ibw_init
  */
-typedef struct _ibw_initattr {
+struct ibw_initattr {
        const char *name;
        const char *value;
-} ibw_initattr;
+};
 
 /*
  * Callback function definition which should inform you about
  * connection state change
- * This callback is invoked from within ibw_process_event.
+ * This callback is invoked whenever server or client connection changes.
  * Both <conn> and <ctx> can be NULL if their state didn't change.
  * Return nonzero on error.
  */
@@ -77,12 +77,13 @@ typedef int (*ibw_connstate_fn_t)(ibw_ctx *ctx, ibw_conn *conn);
 
 /*
  * Callback function definition which should process incoming packets
- * This callback is invoked from within ibw_process_event.
+ * This callback is invoked whenever any message arrives.
  * Return nonzero on error.
  *
- * Important: you mustn't store buf pointer for later use. Process its contents before returning.
+ * Important: you mustn't store buf pointer for later use.
+ * Process its contents before returning.
  */
-typedef int (*ibw_receive_fn_t)(ibw_conn *conn, void *buf, int n);
+typedef int (*ibw_receive_fn_t)(struct ibw_conn *conn, void *buf, int n);
 
 /*
  * settings: array of (name, value) pairs
@@ -102,11 +103,11 @@ typedef int (*ibw_receive_fn_t)(ibw_conn *conn, void *buf, int n);
  *    it will close resources by destructor
  *    connections(ibw_conn *) must have been closed prior talloc_free
  */
-ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
+struct ibw_ctx *ibw_init(struct ibw_initattr *attr, int nattr,
        void *ctx_userdata,
        ibw_connstate_fn_t ibw_connstate,
        ibw_receive_fn_t ibw_receive,
-       event_content *ectx,
+       struct event_context *ectx,
        int max_msg_size);
 
 /*
@@ -117,7 +118,7 @@ ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
  * During that time, you mustn't send/recv/disconnect any more.
  * Only after ctx->state=IBWS_STOPPED you can talloc_free the ctx.
  */
-int ibw_stop(ibw_ctx *ctx);
+int ibw_stop(struct ibw_ctx *ctx);
 
 /*************** connection initiation - like stream sockets *****/
 
@@ -127,7 +128,7 @@ int ibw_stop(ibw_ctx *ctx);
  *
  * return 0 on success
  */
-int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr);
+int ibw_bind(struct ibw_ctx *ctx, struct sockaddr_in *my_addr);
 
 /*
  * works like socket listen
@@ -137,7 +138,7 @@ int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr);
  *
  * returns 0 on success
  */
-int ibw_listen(ibw_ctx *ctx, int backlog);
+int ibw_listen(struct ibw_ctx *ctx, int backlog);
 
 /*
  * works like socket accept
@@ -151,7 +152,7 @@ int ibw_listen(ibw_ctx *ctx, int backlog);
  *
  * Important: you won't get remote IP address (only internal conn info)
  */
-int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata);
+int ibw_accept(struct ibw_ctx *ctx, struct ibw_conn *conn, void *conn_userdata);
 
 /*
  * Needs a normal internet address here
@@ -162,7 +163,7 @@ int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata);
  * You have +1 waiting here: you will get ibw_conn (having the
  * same <conn_userdata> member) structure in ibw_connstate_fn_t.
  */
-int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata);
+int ibw_connect(struct ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata);
 
 /*
  * Sends out a disconnect request.
@@ -173,7 +174,7 @@ int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata
  * You mustn't talloc_free <conn> yet right after this,
  * first wait for IBWC_DISCONNECTED.
  */
-void ibw_disconnect(ibw_conn *conn);
+void ibw_disconnect(struct ibw_conn *conn);
 
 /************ Infiniband specific event loop wrapping ******************/
 
@@ -185,7 +186,7 @@ void ibw_disconnect(ibw_conn *conn);
  *
  * Returns 0 on success.
  */
-int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key);
+int ibw_alloc_send_buf(struct ibw_conn *conn, void **buf, void **key);
 
 /*
  * Send the message in one
@@ -195,7 +196,7 @@ int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key);
  *
  * You mustn't use (buf, key) any more for sending.
  */
-int ibw_send(ibw_conn *conn, void *buf, void *key, int n);
+int ibw_send(struct ibw_conn *conn, void *buf, void *key, int n);
 
 /*
  * Retrieves the last error
index 4f0f11f605c8c505a218f98d9fed163b47af069a..b6d8eb2bc2fc3874bdc4a382f8467486a944f8ff 100644 (file)
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-typedef struct _ibw_opts {
+struct ibw_opts {
        int     max_send_wr;
        int     max_recv_wr;
-} ibw_opts;
+};
 
-typedef struct _ibw_wr {
+struct ibw_wr {
        char    *msg; /* initialized in ibw_init_memory once per connection */
        int     wr_id; /* position in wr_index list; also used as wr id */
        struct _ibw_wr *next, *prev; /* in wr_list_avail or wr_list_used */
-} ibw_wr;
+};
 
-typedef enum {
-       IWINT_INIT = 0,
-       IWINT_ADDR_RESOLVED,
-       IWINT_ROUTE_RESOLVED,
-       IWINT_ERROR
-} ibw_state_ctx;
-
-typedef struct _ibw_ctx_priv {
+struct ibw_ctx_priv {
        struct event_context *ectx;
 
-       ibw_opts opts;
+       struct ibw_opts opts;
 
        struct rdma_cm_id       *cm_id; /* server cm id */
 
@@ -50,6 +43,7 @@ typedef struct _ibw_ctx_priv {
        struct fd_event *cm_channel_event;
 
        struct ibv_pd          *pd;
+       enum iwint_state_ctx    state2;
 
        ibw_connstate_fn_t connstate_func; /* see ibw_init */
        ibw_receive_fn_t receive_func; /* see ibw_init */
@@ -57,9 +51,9 @@ typedef struct _ibw_ctx_priv {
        long    pagesize; /* sysconf result for memalign */
        int     qsize; /* opts.max_send_wr + opts.max_recv_wr */
        int     max_msg_size; /* see ibw_init */
-} ibw_ctx_priv;
+};
 
-typedef struct _ibw_conn_priv {
+struct ibw_conn_priv {
        struct ibv_comp_channel *verbs_channel;
        struct fd_event *verbs_channel_event;
 
@@ -69,8 +63,8 @@ typedef struct _ibw_conn_priv {
        struct ibv_cq   *cq; /* qp is in cm_id */
        struct ibv_mr *mr;
        char *buf; /* fixed size (qsize * opts.max_msg_size) buffer for send/recv */
-       ibw_wr *wr_list_avail;
-       ibw_wr *wr_list_used;
-       ibw_wr **wr_index; /* array[0..(qsize-1)] of (ibw_wr *) */
-} ibw_conn_priv;
+       struct ibw_wr *wr_list_avail;
+       struct ibw_wr *wr_list_used;
+       struct ibw_wr **wr_index; /* array[0..(qsize-1)] of (ibw_wr *) */
+};