mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [2/4] incubator-mynewt-core git commit: oic; copy outgoing oc_message to os_mbuf at coap_send_message().
Date Thu, 08 Dec 2016 22:55:31 GMT
oic; copy outgoing oc_message to os_mbuf at coap_send_message().


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/7384127a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/7384127a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/7384127a

Branch: refs/heads/develop
Commit: 7384127ad9cca0559de881b44514d0b18425a5d6
Parents: 0ecba03
Author: Marko Kiiskila <marko@runtime.io>
Authored: Thu Dec 8 12:51:33 2016 -0800
Committer: Marko Kiiskila <marko@runtime.io>
Committed: Thu Dec 8 14:55:15 2016 -0800

----------------------------------------------------------------------
 net/oic/include/oic/oc_buffer.h    |   2 +-
 net/oic/src/api/oc_buffer.c        | 122 ++++++++++----------------------
 net/oic/src/messaging/coap/coap.c  |  31 +++++++-
 net/oic/src/port/oc_connectivity.h |   1 -
 4 files changed, 65 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7384127a/net/oic/include/oic/oc_buffer.h
----------------------------------------------------------------------
diff --git a/net/oic/include/oic/oc_buffer.h b/net/oic/include/oic/oc_buffer.h
index 2d67109..ff581da 100644
--- a/net/oic/include/oic/oc_buffer.h
+++ b/net/oic/include/oic/oc_buffer.h
@@ -32,7 +32,7 @@ void oc_message_add_ref(struct oc_message *message);
 void oc_message_unref(struct oc_message *message);
 
 void oc_recv_message(struct os_mbuf *m);
-void oc_send_message(struct oc_message *message);
+void oc_send_message(struct os_mbuf *m);
 
 #ifdef __cplusplus
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7384127a/net/oic/src/api/oc_buffer.c
----------------------------------------------------------------------
diff --git a/net/oic/src/api/oc_buffer.c b/net/oic/src/api/oc_buffer.c
index 6a38301..668c698 100644
--- a/net/oic/src/api/oc_buffer.c
+++ b/net/oic/src/api/oc_buffer.c
@@ -36,13 +36,8 @@ static struct os_mempool oc_buffers;
 static uint8_t oc_buffer_area[OS_MEMPOOL_BYTES(MAX_NUM_CONCURRENT_REQUESTS * 2,
       sizeof(oc_message_t))];
 
-static void oc_buffer_handler(struct os_event *);
-
 static struct os_mqueue oc_inq;
-static struct oc_message *oc_buffer_outq;
-static struct os_event oc_buffer_ev = {
-    .ev_cb = oc_buffer_handler
-};
+static struct os_mqueue oc_outq;
 
 oc_message_t *
 oc_allocate_message(void)
@@ -51,12 +46,12 @@ oc_allocate_message(void)
 
     if (message) {
         message->length = 0;
-        message->next = 0;
         message->ref_count = 1;
         LOG("buffer: Allocated TX/RX buffer; num free: %d\n",
           oc_buffers.mp_num_free);
     } else {
         LOG("buffer: No free TX/RX buffers!\n");
+        assert(0);
     }
     return message;
 }
@@ -82,20 +77,6 @@ oc_message_unref(oc_message_t *message)
     }
 }
 
-static void
-oc_queue_msg(struct oc_message **head, struct oc_message *msg)
-{
-    struct oc_message *tmp;
-
-    msg->next = NULL; /* oc_message has been oc_list once, clear next */
-    if (!*head) {
-        *head = msg;
-    } else {
-        for (tmp = *head; tmp->next; tmp = tmp->next);
-        tmp->next = msg;
-    }
-}
-
 void
 oc_recv_message(struct os_mbuf *m)
 {
@@ -106,69 +87,52 @@ oc_recv_message(struct os_mbuf *m)
 }
 
 void
-oc_send_message(oc_message_t *message)
+oc_send_message(struct os_mbuf *m)
 {
-    oc_queue_msg(&oc_buffer_outq, message);
-    os_eventq_put(oc_evq_get(), &oc_buffer_ev);
+    int rc;
+
+    rc = os_mqueue_put(&oc_outq, oc_evq_get(), m);
+    assert(rc == 0);
 }
 
 static void
-oc_buffer_tx(struct oc_message *msg)
+oc_buffer_tx(struct os_event *ev)
 {
     struct os_mbuf *m;
-    struct oc_endpoint *oe;
-    int rc;
-
-    /* get a packet header */
-    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
-    if (!m) {
-        ERROR("oc_buffer_tx: failed to alloc mbuf\n");
-        oc_message_unref(msg);
-        return;
-    }
-
-    /* add this data to the mbuf */
-    rc = os_mbuf_append(m, msg->data, msg->length);
-    if (rc != 0) {
-        ERROR("oc_buffer_tx: could not append data\n");
-        oc_message_unref(msg);
-        return;
-    }
-
-    oe = OC_MBUF_ENDPOINT(m);
-    memcpy(oe, &msg->endpoint, sizeof(msg->endpoint));
-
-    oc_message_unref(msg);
 
+    while ((m = os_mqueue_get(&oc_outq)) != NULL) {
 #ifdef OC_CLIENT
-    if (oe->flags & MULTICAST) {
-        LOG("Outbound network event: multicast request\n");
-        oc_send_multicast_message(m);
-    } else {
+        struct oc_endpoint *oe;
+        oe = OC_MBUF_ENDPOINT(m);
+        if (oe->flags & MULTICAST) {
+            LOG("oc_buffer_tx: multicast\n");
+            oc_send_multicast_message(m);
+        } else {
 #endif
 #ifdef OC_SECURITY
-        /* XXX convert this */
-        if (oe->flags & SECURED) {
-            LOG("Outbound network event: forwarding to DTLS\n");
-
-            if (!oc_sec_dtls_connected(oe)) {
-                LOG("Posting INIT_DTLS_CONN_EVENT\n");
-                oc_process_post(&oc_dtls_handler,
-                  oc_events[INIT_DTLS_CONN_EVENT], m);
-            } else {
-                LOG("Posting RI_TO_DTLS_EVENT\n");
-                oc_process_post(&oc_dtls_handler,
-                  oc_events[RI_TO_DTLS_EVENT], m);
-            }
-        } else
+            /* XXX convert this */
+            if (OC_MBUF_ENDPOINT(m)->flags & SECURED) {
+                LOG("oc_buffer_tx: DTLS\n");
+
+                if (!oc_sec_dtls_connected(oe)) {
+                    LOG("oc_buffer_tx: INIT_DTLS_CONN_EVENT\n");
+                    oc_process_post(&oc_dtls_handler,
+                                    oc_events[INIT_DTLS_CONN_EVENT], m);
+                } else {
+                    LOG("oc_buffer_tx: RI_TO_DTLS_EVENT\n");
+                    oc_process_post(&oc_dtls_handler,
+                                    oc_events[RI_TO_DTLS_EVENT], m);
+                }
+            } else
 #endif
-        {
-            LOG("Outbound network event: unicast message\n");
-            oc_send_buffer(m);
-        }
+            {
+                LOG("oc_buffer_tx: unicast\n");
+                oc_send_buffer(m);
+            }
 #ifdef OC_CLIENT
-    }
+        }
 #endif
+    }
 }
 
 static void
@@ -220,26 +184,12 @@ free_msg:
     }
 }
 
-static void
-oc_buffer_handler(struct os_event *ev)
-{
-    struct oc_message *msg;
-
-    while (oc_buffer_outq) {
-        msg = oc_buffer_outq;
-        if (msg) {
-            oc_buffer_outq = msg->next;
-            msg->next = NULL;
-            oc_buffer_tx(msg);
-        }
-    }
-}
-
 void
 oc_buffer_init(void)
 {
     os_mempool_init(&oc_buffers, MAX_NUM_CONCURRENT_REQUESTS * 2,
       sizeof(oc_message_t), oc_buffer_area, "oc_bufs");
     os_mqueue_init(&oc_inq, oc_buffer_rx, NULL);
+    os_mqueue_init(&oc_outq, oc_buffer_tx, NULL);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7384127a/net/oic/src/messaging/coap/coap.c
----------------------------------------------------------------------
diff --git a/net/oic/src/messaging/coap/coap.c b/net/oic/src/messaging/coap/coap.c
index 2230fba..768a65e 100644
--- a/net/oic/src/messaging/coap/coap.c
+++ b/net/oic/src/messaging/coap/coap.c
@@ -439,13 +439,38 @@ coap_serialize_message(coap_packet_t *pkt, uint8_t *buffer, int tcp_hdr)
 }
 /*---------------------------------------------------------------------------*/
 void
-coap_send_message(oc_message_t *message)
+coap_send_message(struct oc_message *msg)
 {
-    LOG("-sending OCF message (%u)-\n", (unsigned int) message->length);
+    struct os_mbuf *m;
+    struct oc_endpoint *oe;
+    int rc;
+
+    LOG("-sending OCF message (%u)-\n", msg->length);
 
     STATS_INC(coap_stats, oframe);
 
-    oc_send_message(message);
+    /* get a packet header */
+    m = os_msys_get_pkthdr(0, sizeof(struct oc_endpoint));
+    if (!m) {
+        ERROR("coap_send_msg: failed to alloc mbuf\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    /* add this data to the mbuf */
+    rc = os_mbuf_append(m, msg->data, msg->length);
+    if (rc != 0) {
+        ERROR("coap_send_msg: could not append data\n");
+        oc_message_unref(msg);
+        return;
+    }
+
+    oe = OC_MBUF_ENDPOINT(m);
+    memcpy(oe, &msg->endpoint, sizeof(msg->endpoint));
+
+    oc_message_unref(msg);
+
+    oc_send_message(m);
 }
 
 /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7384127a/net/oic/src/port/oc_connectivity.h
----------------------------------------------------------------------
diff --git a/net/oic/src/port/oc_connectivity.h b/net/oic/src/port/oc_connectivity.h
index e8762a3..0735b67 100644
--- a/net/oic/src/port/oc_connectivity.h
+++ b/net/oic/src/port/oc_connectivity.h
@@ -58,7 +58,6 @@ typedef struct oc_endpoint {
                                           .address = { __VA_ARGS__ } } }
 
 typedef struct oc_message {
-    struct oc_message *next;
     oc_endpoint_t endpoint;
     size_t length;
     uint8_t ref_count;


Mime
View raw message