Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
code
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
ReadMailReallyFast
code
Commits
0e6994b2
Verified
Commit
0e6994b2
authored
4 years ago
by
Benny Baumann
Browse files
Options
Downloads
Patches
Plain Diff
chg: Split ioqueue into header+impl
parent
01ba45c8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/net/ioqueue.cpp
+79
-0
79 additions, 0 deletions
src/net/ioqueue.cpp
src/net/ioqueue.hpp
+17
-52
17 additions, 52 deletions
src/net/ioqueue.hpp
with
96 additions
and
52 deletions
src/net/ioqueue.cpp
0 → 100644
+
79
−
0
View file @
0e6994b2
#include
"net/ioqueue.hpp"
namespace
rmrf
::
net
{
iorecord
::
iorecord
()
:
offset
{},
data
{}
{}
iorecord
::
iorecord
(
const
void
*
buf
,
size_t
size
)
:
offset
{
0
},
data
((
const
uint8_t
*
)
buf
,
(
const
uint8_t
*
)
buf
+
size
)
{
// Nothing special to do here ...
}
iorecord
::
iorecord
(
const
iorecord
&
other
)
:
offset
{
other
.
offset
},
data
{
other
.
data
}
{
// NOP
}
iorecord
::
iorecord
(
iorecord
&&
other
)
:
offset
(
other
.
offset
),
data
(
std
::
forward
<
std
::
vector
<
uint8_t
>>
(
other
.
data
))
{
// Nothing special to do here ...
}
size_t
iorecord
::
size
()
const
{
return
this
->
data
.
size
()
-
this
->
offset
;
}
bool
iorecord
::
empty
()
const
{
return
!
this
->
size
();
}
void
*
iorecord
::
ptr
()
const
{
return
(
void
*
)(
this
->
data
.
data
()
+
this
->
offset
);
}
void
iorecord
::
advance
(
size_t
amount
)
{
this
->
offset
+=
std
::
min
(
amount
,
this
->
size
());
}
ioqueue
::
ioqueue
()
:
queue
{}
{
// NOP
}
ioqueue
::~
ioqueue
()
{
// NOP
}
bool
ioqueue
::
empty
()
const
{
return
this
->
queue
.
empty
();
}
void
ioqueue
::
push_back
(
const
iorecord
&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
push_back
(
data
);
}
}
void
ioqueue
::
push_back
(
iorecord
&&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
emplace_back
(
std
::
forward
<
iorecord
>
(
data
));
}
}
void
ioqueue
::
push_front
(
const
iorecord
&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
push_front
(
data
);
}
}
void
ioqueue
::
push_front
(
iorecord
&&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
emplace_front
(
std
::
forward
<
iorecord
>
(
data
));
}
}
iorecord
ioqueue
::
pop_front
()
{
if
(
this
->
empty
())
{
return
iorecord
{};
}
iorecord
result
=
this
->
queue
.
front
();
this
->
queue
.
pop_front
();
return
result
;
}
}
// namespace rmrf::net
This diff is collapsed.
Click to expand it.
src/net/ioqueue.hpp
+
17
−
52
View file @
0e6994b2
...
@@ -13,29 +13,17 @@ namespace rmrf::net {
...
@@ -13,29 +13,17 @@ namespace rmrf::net {
size_t
offset
;
size_t
offset
;
std
::
vector
<
uint8_t
>
data
;
std
::
vector
<
uint8_t
>
data
;
public:
public:
iorecord
()
:
offset
{},
data
{}
{}
iorecord
();
iorecord
(
const
void
*
buf
,
size_t
size
)
:
iorecord
(
const
void
*
buf
,
size_t
size
);
offset
{
0
},
data
((
const
uint8_t
*
)
buf
,
(
const
uint8_t
*
)
buf
+
size
)
{
iorecord
(
const
iorecord
&
other
);
// Nothing special to do here ...
iorecord
(
iorecord
&&
other
);
};
iorecord
(
iorecord
&&
other
)
:
offset
(
other
.
offset
),
data
(
std
::
forward
<
iorecord
>
(
other
.
data
))
{
// Nothing special to do here ...
};
public:
public:
size_t
size
()
const
{
size_t
size
()
const
;
return
this
->
data
.
size
()
-
this
->
offset
;
bool
empty
()
const
;
}
void
*
ptr
()
const
;
bool
empty
()
const
{
return
!
this
->
size
();
}
void
*
ptr
()
const
{
return
(
void
*
)(
this
->
data
.
data
()
+
this
->
offset
);
}
void
advance
(
size_t
amount
)
{
void
advance
(
size_t
amount
);
this
->
offset
+=
std
::
min
(
amount
,
this
->
size
());
}
};
};
class
ioqueue
{
class
ioqueue
{
...
@@ -43,41 +31,18 @@ namespace rmrf::net {
...
@@ -43,41 +31,18 @@ namespace rmrf::net {
std
::
deque
<
iorecord
>
queue
;
std
::
deque
<
iorecord
>
queue
;
public:
public:
bool
empty
()
const
{
ioqueue
();
return
this
->
queue
.
empty
();
~
ioqueue
();
}
void
push_back
(
const
iorecord
&
data
)
{
bool
empty
()
const
;
if
(
!
data
.
empty
())
{
this
->
queue
.
push_back
(
data
);
}
}
void
push_back
(
iorecord
&&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
emplace_back
(
std
::
forward
(
data
));
}
}
void
push_front
(
const
iorecord
&
data
)
{
void
push_back
(
const
iorecord
&
data
);
if
(
!
data
.
empty
())
{
void
push_back
(
iorecord
&&
data
);
this
->
queue
.
push_front
(
data
);
}
}
void
push_front
(
iorecord
&&
data
)
{
if
(
!
data
.
empty
())
{
this
->
queue
.
emplace_front
(
std
::
forward
(
data
));
}
}
iorecord
pop_front
()
{
void
push_front
(
const
iorecord
&
data
);
if
(
this
->
empty
())
{
void
push_front
(
iorecord
&&
data
);
return
iorecord
{};
}
iorecord
result
=
this
->
queue
.
front
();
iorecord
pop_front
();
this
->
queue
.
pop_front
();
return
result
;
}
};
};
}
}
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