Skip to content

Commit

Permalink
dtls: use dynamic sizes for netq when possible
Browse files Browse the repository at this point in the history
When each package stored in netq is dynamically allocated we should not
make space for DTLS_MAX_BUF, but allocate as many bytes as needed for
this specific packet. This reduces the space needed for the
retransmission queue by ~50% on a Linux system.

Signed-off-by: Hauke Mehrtens <[email protected]>
  • Loading branch information
hauke committed Dec 19, 2013
1 parent c0ed926 commit f9ca99d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ dtls_send_multi(dtls_context_t *ctx, dtls_peer_t *peer,
if ((type == DTLS_CT_HANDSHAKE && buf_array[0][0] != DTLS_HT_HELLO_VERIFY_REQUEST) ||
type == DTLS_CT_CHANGE_CIPHER_SPEC) {
/* copy handshake messages other than HelloVerify into retransmit buffer */
netq_t *n = netq_node_new();
netq_t *n = netq_node_new(overall_len);
if (n) {
dtls_tick_t now;
dtls_ticks(&now);
Expand Down Expand Up @@ -3327,7 +3327,7 @@ handle_handshake(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session,
node = netq_next(node);
}

n = netq_node_new();
n = netq_node_new(data_length);
if (!n) {
dtls_warn("no space in reoder buffer\n");
return 0;
Expand Down
10 changes: 5 additions & 5 deletions netq.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <stdlib.h>

static inline netq_t *
netq_malloc_node() {
return (netq_t *)malloc(sizeof(netq_t));
netq_malloc_node(size_t size) {
return (netq_t *)malloc(sizeof(netq_t) + size);
}

static inline void
Expand All @@ -41,7 +41,7 @@ netq_free_node(netq_t *node) {
MEMB(netq_storage, netq_t, NETQ_MAXCNT);

static inline netq_t *
netq_malloc_node() {
netq_malloc_node(size_t size) {
return (netq_t *)memb_alloc(&netq_storage);
}

Expand Down Expand Up @@ -107,9 +107,9 @@ netq_t *netq_pop_first(list_t queue) {
}

netq_t *
netq_node_new() {
netq_node_new(size_t size) {
netq_t *node;
node = netq_malloc_node();
node = netq_malloc_node(size);

#ifndef NDEBUG
if (!node)
Expand Down
6 changes: 5 additions & 1 deletion netq.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ typedef struct netq_t {
unsigned char retransmit_cnt; /**< retransmission counter, will be removed when zero */

size_t length; /**< actual length of data */
#ifndef WITH_CONTIKI
unsigned char data[]; /**< the datagram to send */
#else
netq_packet_t data; /**< the datagram to send */
#endif
} netq_t;

#ifndef WITH_CONTIKI
Expand Down Expand Up @@ -76,7 +80,7 @@ void netq_node_free(netq_t *node);
void netq_delete_all(list_t queue);

/** Creates a new node suitable for adding to a netq_t queue. */
netq_t *netq_node_new();
netq_t *netq_node_new(size_t size);

/**
* Returns a pointer to the first item in given queue or NULL if
Expand Down

0 comments on commit f9ca99d

Please sign in to comment.