From 13db03534b26304cab537953f99c2db8755d753b Mon Sep 17 00:00:00 2001
From: Timo Dritschler <timo.dritschler@kit.edu>
Date: Mon, 16 Feb 2015 17:35:43 +0100
Subject: Fixed KIRO Client allocating new memory on each ACK_RDMA message

---
 src/kiro-client.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/kiro-client.c b/src/kiro-client.c
index b9c33c5..01f4fb0 100644
--- a/src/kiro-client.c
+++ b/src/kiro-client.c
@@ -205,18 +205,23 @@ process_rdma_event (GIOChannel *source, GIOCondition condition, gpointer data)
 
     if (type == KIRO_ACK_RDMA) {
         g_debug ("Got RDMI Access information from Server");
-        ctx->peer_mr = (((struct kiro_ctrl_msg *) (ctx->cf_mr_recv->mem))->peer_mri);
-        g_debug ("Expected Memory Size is: %zu", 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) {
-            //FIXME: Connection teardown in an event handler routine? Not a good
-            //idea...
-            g_critical ("Failed to allocate memory for receive buffer (Out of memory?)");
-            rdma_disconnect (priv->conn);
-            kiro_destroy_connection_context (&ctx);
-            rdma_destroy_ep (priv->conn);
-            return TRUE;
+        if (ctx->rdma_mr) {
+            g_debug ("But memory is already allocated. Ignoring");
+        }
+        else {
+            ctx->peer_mr = (((struct kiro_ctrl_msg *) (ctx->cf_mr_recv->mem))->peer_mri);
+            g_debug ("Expected Memory Size is: %zu", 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) {
+                //FIXME: Connection teardown in an event handler routine? Not a good
+                //idea...
+                g_critical ("Failed to allocate memory for receive buffer (Out of memory?)");
+                rdma_disconnect (priv->conn);
+                kiro_destroy_connection_context (&ctx);
+                rdma_destroy_ep (priv->conn);
+                return TRUE;
+            }
         }
     }
     if (type == KIRO_PONG) {
-- 
cgit v1.2.3