Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2098A200BD5 for ; Thu, 8 Dec 2016 23:55:36 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1F5EA160B0A; Thu, 8 Dec 2016 22:55:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 49763160B27 for ; Thu, 8 Dec 2016 23:55:35 +0100 (CET) Received: (qmail 66679 invoked by uid 500); 8 Dec 2016 22:55:34 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 66670 invoked by uid 99); 8 Dec 2016 22:55:34 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Dec 2016 22:55:34 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 19BCD18BB8D for ; Thu, 8 Dec 2016 22:55:34 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -6.218 X-Spam-Level: X-Spam-Status: No, score=-6.218 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-2.999, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id M4apTWAkiA1S for ; Thu, 8 Dec 2016 22:55:32 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 390FD5FC41 for ; Thu, 8 Dec 2016 22:55:31 +0000 (UTC) Received: (qmail 66498 invoked by uid 99); 8 Dec 2016 22:55:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Dec 2016 22:55:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2E729E36E0; Thu, 8 Dec 2016 22:55:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: marko@apache.org To: commits@mynewt.incubator.apache.org Date: Thu, 08 Dec 2016 22:55:31 -0000 Message-Id: <16897529c9f34894af77c392ba8926c3@git.apache.org> In-Reply-To: <40d2dea0a80a4bbda17321cdf94ced77@git.apache.org> References: <40d2dea0a80a4bbda17321cdf94ced77@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/4] incubator-mynewt-core git commit: oic; copy outgoing oc_message to os_mbuf at coap_send_message(). archived-at: Thu, 08 Dec 2016 22:55:36 -0000 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 Authored: Thu Dec 8 12:51:33 2016 -0800 Committer: Marko Kiiskila 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;