You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/13 20:55:41 UTC
[28/50] [abbrv] incubator-mynewt-core git commit: mbuf:
os_mbuf_appendfrom
mbuf: os_mbuf_appendfrom
/**
* Reads data from one mbuf and appends it to another. On error, the
* specified data range may be partially appended. Neither mbuf is
* required to contain an mbuf packet header.
*
* @param dst The mbuf to append to.
* @param src The mbuf to copy data from.
* @param src_off The absolute offset within the source
* mbuf chain to read from.
* @param len The number of bytes to append.
*/
int
os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
uint16_t src_off, uint16_t len)
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/98181d76
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/98181d76
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/98181d76
Branch: refs/heads/develop
Commit: 98181d7604760f63ab9bac3a02b78865d38719b5
Parents: fd4a12a
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jul 8 19:45:41 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 16:43:34 2016 -0700
----------------------------------------------------------------------
libs/os/include/os/os_mbuf.h | 3 +++
libs/os/src/os_mbuf.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98181d76/libs/os/include/os/os_mbuf.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_mbuf.h b/libs/os/include/os/os_mbuf.h
index 831d770..82aef4d 100644
--- a/libs/os/include/os/os_mbuf.h
+++ b/libs/os/include/os/os_mbuf.h
@@ -267,6 +267,9 @@ int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst);
/* Append data onto a mbuf */
int os_mbuf_append(struct os_mbuf *m, const void *, uint16_t);
+int os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
+ uint16_t src_off, uint16_t len);
+
/* Free a mbuf */
int os_mbuf_free(struct os_mbuf *mb);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/98181d76/libs/os/src/os_mbuf.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_mbuf.c b/libs/os/src/os_mbuf.c
index 65afc01..92c8bcc 100644
--- a/libs/os/src/os_mbuf.c
+++ b/libs/os/src/os_mbuf.c
@@ -509,6 +509,45 @@ err:
return (rc);
}
+/**
+ * Reads data from one mbuf and appends it to another. On error, the specified
+ * data range may be partially appended. Neither mbuf is required to contain
+ * an mbuf packet header.
+ *
+ * @param dst The mbuf to append to.
+ * @param src The mbuf to copy data from.
+ * @param src_off The absolute offset within the source mbuf
+ * chain to read from.
+ * @param len The number of bytes to append.
+ */
+int
+os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src,
+ uint16_t src_off, uint16_t len)
+{
+ const struct os_mbuf *src_cur_om;
+ uint16_t chunk_sz;
+ int src_cur_off;
+ int rc;
+
+ src_cur_om = os_mbuf_off(src, src_off, &src_cur_off);
+ if (src_cur_om == NULL) {
+ return OS_EINVAL;
+ }
+
+ while (len > 0) {
+ chunk_sz = min(len, src_cur_om->om_len - src_cur_off);
+ rc = os_mbuf_append(dst, src_cur_om->om_data + src_cur_off, chunk_sz);
+ if (rc != 0) {
+ return rc;
+ }
+
+ len -= chunk_sz;
+ src_cur_om = SLIST_NEXT(src_cur_om, om_next);
+ src_cur_off = 0;
+ }
+
+ return 0;
+}
/**
* Duplicate a chain of mbufs. Return the start of the duplicated chain.