summaryrefslogtreecommitdiffstats
path: root/src/kiro-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kiro-client.c')
-rw-r--r--src/kiro-client.c228
1 files changed, 118 insertions, 110 deletions
diff --git a/src/kiro-client.c b/src/kiro-client.c
index 1fd7860..b930595 100644
--- a/src/kiro-client.c
+++ b/src/kiro-client.c
@@ -53,23 +53,25 @@ struct _KiroClientPrivate {
/* (Not accessible by properties) */
struct rdma_event_channel *ec; // Main Event Channel
struct rdma_cm_id *conn; // Connection to the Server
-
+
};
G_DEFINE_TYPE (KiroClient, kiro_client, G_TYPE_OBJECT);
-KiroClient*
-kiro_client_new (void) {
+KiroClient *
+kiro_client_new (void)
+{
return g_object_new (KIRO_TYPE_CLIENT, NULL);
}
-static void kiro_client_init (KiroClient *self)
+static void
+kiro_client_init (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- memset(priv, 0, sizeof(&priv));
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+ memset (priv, 0, sizeof (&priv));
}
static void
@@ -83,177 +85,183 @@ kiro_client_finalize (GObject *object)
static void
kiro_client_class_init (KiroClientClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = kiro_client_finalize;
- g_type_class_add_private(klass, sizeof(KiroClientPrivate));
+ g_type_class_add_private (klass, sizeof (KiroClientPrivate));
}
-int kiro_client_connect (KiroClient *self, char *address, char* port)
+int
+kiro_client_connect (KiroClient *self, char *address, char *port)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
- if(priv->conn)
- {
- printf("Already connected to server.\n");
+ if (priv->conn) {
+ printf ("Already connected to server.\n");
return -1;
}
-
+
struct rdma_addrinfo hints, *res_addrinfo;
- memset(&hints, 0, sizeof(hints));
+
+ memset (&hints, 0, sizeof (hints));
+
hints.ai_port_space = RDMA_PS_IB;
- if(rdma_getaddrinfo(address, port, &hints, &res_addrinfo))
- {
- printf("Failed to contruct address information for %s:%s\n",address, port);
+
+ if (rdma_getaddrinfo (address, port, &hints, &res_addrinfo)) {
+ printf ("Failed to contruct address information for %s:%s\n", address, port);
return -1;
}
- printf("Address information created.\n");
-
+
+ printf ("Address information created.\n");
struct ibv_qp_init_attr qp_attr;
- memset(&qp_attr, 0, sizeof(qp_attr));
+ memset (&qp_attr, 0, sizeof (qp_attr));
qp_attr.cap.max_send_wr = 10;
qp_attr.cap.max_recv_wr = 10;
qp_attr.cap.max_send_sge = 1;
qp_attr.cap.max_recv_sge = 1;
qp_attr.qp_context = priv->conn;
qp_attr.sq_sig_all = 1;
-
- if(rdma_create_ep(&(priv->conn), res_addrinfo, NULL, &qp_attr))
- {
- printf("Endpoint creation failed with error: %i\n", errno);
+
+ if (rdma_create_ep (& (priv->conn), res_addrinfo, NULL, &qp_attr)) {
+ printf ("Endpoint creation failed with error: %i\n", errno);
return -1;
}
- printf("Route to server resolved.\n");
-
- struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc(1,sizeof(struct kiro_connection_context));
- if(!ctx)
- {
- printf("Failed to create connection context.\n");
- rdma_destroy_ep(priv->conn);
+
+ printf ("Route to server resolved.\n");
+ struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context));
+
+ if (!ctx) {
+ printf ("Failed to create connection context.\n");
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc(1, sizeof(struct kiro_rdma_mem));
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to allocate Control Flow Memory Container.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ ctx->cf_mr_send = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+ ctx->cf_mr_recv = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem));
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to allocate Control Flow Memory Container.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- ctx->cf_mr_recv = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- ctx->cf_mr_send = kiro_create_rdma_memory(priv->conn->pd, sizeof(struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
- if(!ctx->cf_mr_recv || !ctx->cf_mr_send)
- {
- printf("Failed to register control message memory.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ ctx->cf_mr_recv = kiro_create_rdma_memory (priv->conn->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+ ctx->cf_mr_send = kiro_create_rdma_memory (priv->conn->pd, sizeof (struct kiro_ctrl_msg), IBV_ACCESS_LOCAL_WRITE);
+
+ if (!ctx->cf_mr_recv || !ctx->cf_mr_send) {
+ printf ("Failed to register control message memory.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof(struct kiro_ctrl_msg);
+
+ ctx->cf_mr_recv->size = ctx->cf_mr_send->size = sizeof (struct kiro_ctrl_msg);
priv->conn->context = ctx;
-
- if(rdma_post_recv(priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr))
- {
- printf("Posting preemtive receive for connection failed with error: %i\n", errno);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_post_recv (priv->conn, priv->conn, ctx->cf_mr_recv->mem, ctx->cf_mr_recv->size, ctx->cf_mr_recv->mr)) {
+ printf ("Posting preemtive receive for connection failed with error: %i\n", errno);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
- if(rdma_connect(priv->conn, NULL))
- {
- printf("Failed to establish connection to the server.\n");
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_connect (priv->conn, NULL)) {
+ printf ("Failed to establish connection to the server.\n");
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Connected to server.\n");
-
-
+
+ printf ("Connected to server.\n");
struct ibv_wc wc;
- if(rdma_get_recv_comp(priv->conn, &wc) < 0)
- {
- printf("Failure waiting for POST from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_get_recv_comp (priv->conn, &wc) < 0) {
+ printf ("Failure waiting for POST from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Got Message from Server.\n");
- ctx->peer_mr = (((struct kiro_ctrl_msg *)(ctx->cf_mr_recv->mem))->peer_mri);
- printf("Expected Memory Size is: %u\n",ctx->peer_mr.length);
-
- ctx->rdma_mr = kiro_create_rdma_memory(priv->conn->pd, ctx->peer_mr.length, IBV_ACCESS_LOCAL_WRITE);
- if(!ctx->rdma_mr)
- {
- printf("Failed to allocate memory for receive buffer.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ printf ("Got Message from Server.\n");
+ ctx->peer_mr = (((struct kiro_ctrl_msg *) (ctx->cf_mr_recv->mem))->peer_mri);
+ printf ("Expected Memory Size is: %u\n", ctx->peer_mr.length);
+ ctx->rdma_mr = kiro_create_rdma_memory (priv->conn->pd, ctx->peer_mr.length, IBV_ACCESS_LOCAL_WRITE);
+
+ if (!ctx->rdma_mr) {
+ printf ("Failed to allocate memory for receive buffer.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
- printf("Connection setup completed successfully!\n");
-
+
+ printf ("Connection setup completed successfully!\n");
return 0;
}
-int kiro_client_sync (KiroClient *self)
-{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
+int
+kiro_client_sync (KiroClient *self)
+{
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
-
- if(rdma_post_read(priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, ctx->peer_mr.addr, ctx->peer_mr.rkey))
- {
- printf("Failed to read from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_post_read (priv->conn, priv->conn, ctx->rdma_mr->mem, ctx->peer_mr.length, ctx->rdma_mr->mr, 0, ctx->peer_mr.addr, ctx->peer_mr.rkey)) {
+ printf ("Failed to read from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
-
+
struct ibv_wc wc;
- if(rdma_get_send_comp(priv->conn, &wc) < 0)
- {
- printf("Failure reading from server.\n");
- rdma_disconnect(priv->conn);
- kiro_destroy_connection_context(&ctx);
- rdma_destroy_ep(priv->conn);
+
+ if (rdma_get_send_comp (priv->conn, &wc) < 0) {
+ printf ("Failure reading from server.\n");
+ rdma_disconnect (priv->conn);
+ kiro_destroy_connection_context (&ctx);
+ rdma_destroy_ep (priv->conn);
return -1;
}
+
return 0;
}
-void* kiro_client_get_memory (KiroClient *self)
+void *
+kiro_client_get_memory (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- if(!priv->conn)
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+
+ if (!priv->conn)
return NULL;
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
- if(!ctx->rdma_mr)
+
+ if (!ctx->rdma_mr)
return NULL;
-
+
return ctx->rdma_mr->mem;
}
-size_t kiro_client_get_memory_size (KiroClient *self)
+size_t
+kiro_client_get_memory_size (KiroClient *self)
{
- KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE(self);
- if(!priv->conn)
+ KiroClientPrivate *priv = KIRO_CLIENT_GET_PRIVATE (self);
+
+ if (!priv->conn)
return 0;
struct kiro_connection_context *ctx = (struct kiro_connection_context *)priv->conn->context;
- if(!ctx->rdma_mr)
+
+ if (!ctx->rdma_mr)
return 0;
-
+
return ctx->rdma_mr->size;
}