From 4ee51da5dd22c8e1744811925c150755f68bd042 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Thu, 21 Nov 2013 10:17:55 +0100 Subject: [PATCH] get rid of static buffer this buffer was used for two types of outgoing packets: 1. local msg - msg can be big, there is is no apriori boundary -> use dynamic memory instead 2. transceiver msg - no need to copy msg in this buffer -> transceiver send is blocking --- sys/net/ccn_lite/ccn-lite-relay.c | 5 +---- sys/net/ccn_lite/ccnl-riot-compat.c | 17 +++++++++++++---- sys/net/ccn_lite/util/ccnl-riot-client.c | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/net/ccn_lite/ccn-lite-relay.c b/sys/net/ccn_lite/ccn-lite-relay.c index eef9f28257..01ae24cdf0 100644 --- a/sys/net/ccn_lite/ccn-lite-relay.c +++ b/sys/net/ccn_lite/ccn-lite-relay.c @@ -58,8 +58,6 @@ /** message buffer */ msg_t msg_buffer_relay[RELAY_MSG_BUFFER_SIZE]; -uint8_t packet_out[PAYLOAD_SIZE]; - // ---------------------------------------------------------------------- struct ccnl_relay_s theRelay; @@ -124,8 +122,7 @@ void ccnl_ll_TX(struct ccnl_relay_s *ccnl, struct ccnl_if_s *ifc, { (void) ccnl; /* unused */ - memcpy(&packet_out, &buf->data, buf->datalen); - ifc->sendfunc(packet_out, (uint16_t) buf->datalen, (uint16_t) dest->id); + ifc->sendfunc(buf->data, (uint16_t) buf->datalen, (uint16_t) dest->id); } // ---------------------------------------------------------------------- diff --git a/sys/net/ccn_lite/ccnl-riot-compat.c b/sys/net/ccn_lite/ccnl-riot-compat.c index 996873759b..d7e059066a 100644 --- a/sys/net/ccn_lite/ccnl-riot-compat.c +++ b/sys/net/ccn_lite/ccnl-riot-compat.c @@ -17,6 +17,7 @@ */ #include +#include #include #include @@ -60,13 +61,21 @@ int riot_send_msg(uint8_t *buf, uint16_t size, uint16_t to) DEBUGMSG(1, "this is a RIOT MSG based connection\n"); DEBUGMSG(1, "size=%" PRIu16 " to=%" PRIu16 "\n", size, to); - static riot_ccnl_msg_t rmsg; - rmsg.payload = buf; - rmsg.size = size; + uint8_t *buf2 = malloc(sizeof(riot_ccnl_msg_t) + size); + if (!buf2) { + DEBUGMSG(1, " malloc failed...dorpping msg!\n"); + return 0; + } + + riot_ccnl_msg_t *rmsg = (riot_ccnl_msg_t *) buf2; + rmsg->payload = buf2 + sizeof(riot_ccnl_msg_t); + rmsg->size = size; + + memcpy(rmsg->payload, buf, size); msg_t m; m.type = CCNL_RIOT_MSG; - m.content.ptr = (char *) &rmsg; + m.content.ptr = (char *) rmsg; DEBUGMSG(1, "sending msg to pid=%u\n", to); msg_send(&m, to, 1); diff --git a/sys/net/ccn_lite/util/ccnl-riot-client.c b/sys/net/ccn_lite/util/ccnl-riot-client.c index 4e924e3d95..fe53266ae0 100644 --- a/sys/net/ccn_lite/util/ccnl-riot-client.c +++ b/sys/net/ccn_lite/util/ccnl-riot-client.c @@ -70,11 +70,10 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf) msg_receive(&rep); riot_ccnl_msg_t *rmsg_reply = (riot_ccnl_msg_t *) rep.content.ptr; - memcpy(&compat_small_buf, rmsg_reply->payload, rmsg_reply->size); - unsigned char *data = compat_small_buf; - int datalen = (int) rmsg_reply->size; - DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, compat_small_buf); + unsigned char *data = rmsg_reply->payload; + int datalen = (int) rmsg_reply->size; + DEBUGMSG(1, "%d bytes left; msg from=%u '%s'\n", datalen, rep.sender_pid, data); int scope = 3, aok = 3, minsfx = 0, maxsfx = CCNL_MAX_NAME_COMP, contlen = 0; @@ -96,6 +95,7 @@ int ccnl_riot_client_get(unsigned int relay_pid, char *name, char *reply_buf) free_prefix(p); free_3ptr_list(buf, nonce, ppkd); + ccnl_free(rmsg_reply); if (contlen < CCNL_RIOT_CHUNK_SIZE || CCNL_RIOT_CHUNK_SIZE < contlen) { /* last chunk */