Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
dbbdf3f6
Commit
dbbdf3f6
authored
7 years ago
by
Kaspar Schleiser
Browse files
Options
Downloads
Patches
Plain Diff
sys: introduce iolist
parent
b343ff8a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
sys/include/iolist.h
+87
-0
87 additions, 0 deletions
sys/include/iolist.h
sys/iolist/Makefile
+1
-0
1 addition, 0 deletions
sys/iolist/Makefile
sys/iolist/iolist.c
+61
-0
61 additions, 0 deletions
sys/iolist/iolist.c
with
149 additions
and
0 deletions
sys/include/iolist.h
0 → 100644
+
87
−
0
View file @
dbbdf3f6
/*
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_util_iolist iolist scatter / gather IO
* @ingroup sys_util
* @brief Provides linked-list scatter / gather IO
*
* @{
*
* @file
* @brief iolist scatter / gather IO
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef IOLIST_H
#define IOLIST_H
#include
<unistd.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/** @brief iolist forward declaration */
typedef
struct
iolist
iolist_t
;
/**
* @brief iolist structure definition
*/
struct
iolist
{
iolist_t
*
iol_next
;
/**< ptr to next list entry */
void
*
iol_base
;
/**< ptr to this list entries data */
size_t
iol_len
;
/**< size of data pointet to by ptr */
};
/**
* @brief Count number of entries in an iolist_t
*
* @param[in] iolist iolist to count
*
* @returns number of entries (zero for NULL parameter)
*/
unsigned
iolist_count
(
const
iolist_t
*
iolist
);
/**
* @brief Sum up number of bytes in iolist
*
* This function returns the summed ip lenght values of all entries in @p
* iolist.
*
* @param[in] iolist iolist to sum up
*
* @returns summed up number of bytes or zero if @p iolist == NULL
*/
size_t
iolist_size
(
const
iolist_t
*
iolist
);
/** @brief struct iovec anonymous declaration */
struct
iovec
;
/**
* @brief Create struct iovec from iolist
*
* This function fills an array of struct iovecs with the contents of @p
* iolist. It will write the number of used array entries into @p count.
*
* The caller *must* ensure that @p iov p points to an array of size >= count!
*
* @param[in] iolist iolist to read from
* @param[out] iov ptr to array of struct iovec that will be filled
* @param[out] count number of elements in @p iolist
*
* @returns iolist_size(iolist)
*/
size_t
iolist_to_iovec
(
const
iolist_t
*
iolist
,
struct
iovec
*
iov
,
unsigned
*
count
);
#ifdef __cplusplus
}
#endif
#endif
/* IOLIST_H */
/** @} */
This diff is collapsed.
Click to expand it.
sys/iolist/Makefile
0 → 100644
+
1
−
0
View file @
dbbdf3f6
include
$(RIOTBASE)/Makefile.base
This diff is collapsed.
Click to expand it.
sys/iolist/iolist.c
0 → 100644
+
61
−
0
View file @
dbbdf3f6
/*
* Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup sys_util
* @{
*
* @file
* @brief iolist scatter / gather IO
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include
<sys/uio.h>
#include
"iolist.h"
unsigned
iolist_count
(
const
iolist_t
*
iolist
)
{
unsigned
count
=
0
;
while
(
iolist
)
{
count
++
;
iolist
=
iolist
->
iol_next
;
}
return
count
;
}
size_t
iolist_size
(
const
iolist_t
*
iolist
)
{
size_t
result
=
0
;
while
(
iolist
)
{
result
+=
iolist
->
iol_len
;
iolist
=
iolist
->
iol_next
;
}
return
result
;
}
size_t
iolist_to_iovec
(
const
iolist_t
*
iolist
,
struct
iovec
*
iov
,
unsigned
*
count
)
{
size_t
bytes
=
0
;
unsigned
_count
=
0
;
while
(
iolist
)
{
iov
->
iov_base
=
iolist
->
iol_base
;
iov
->
iov_len
=
iolist
->
iol_len
;
bytes
+=
iov
->
iov_len
;
_count
++
;
iolist
=
iolist
->
iol_next
;
iov
++
;
}
*
count
=
_count
;
return
bytes
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment