Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
emper
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Schmaus
emper
Commits
d7d109a1
Commit
d7d109a1
authored
3 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
[EchoServer] implement random computation in range
parent
9527d2f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/EchoServer.cpp
+32
-9
32 additions, 9 deletions
apps/EchoServer.cpp
with
32 additions
and
9 deletions
apps/EchoServer.cpp
+
32
−
9
View file @
d7d109a1
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#include
"Common.hpp"
#include
"Common.hpp"
#include
"Debug.hpp"
#include
"Debug.hpp"
#include
"Runtime.hpp"
#include
"Runtime.hpp"
#include
"Worker.hpp"
#include
"emper-config.h"
#include
"emper-config.h"
#include
"io.hpp"
#include
"io.hpp"
...
@@ -26,6 +27,7 @@ static const std::string PORT = "12345";
...
@@ -26,6 +27,7 @@ static const std::string PORT = "12345";
static
const
int
BACKLOG
=
1024
;
static
const
int
BACKLOG
=
1024
;
static
unsigned
int
computations_us
=
0
;
static
unsigned
int
computations_us
=
0
;
static
unsigned
int
max_computations_us
=
0
;
static
std
::
atomic
<
bool
>
quit
=
false
;
static
std
::
atomic
<
bool
>
quit
=
false
;
...
@@ -33,8 +35,9 @@ auto main(int argc, char* argv[]) -> int {
...
@@ -33,8 +35,9 @@ auto main(int argc, char* argv[]) -> int {
std
::
string
host
=
HOST
;
std
::
string
host
=
HOST
;
std
::
string
port
=
PORT
;
std
::
string
port
=
PORT
;
if
(
argc
>
3
)
{
if
(
argc
>
4
)
{
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" [port] [computation_us]"
<<
std
::
endl
;
std
::
cerr
<<
"Usage: "
<<
argv
[
0
]
<<
" [port] [computations_us] [max_computations_us]"
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -46,7 +49,19 @@ auto main(int argc, char* argv[]) -> int {
...
@@ -46,7 +49,19 @@ auto main(int argc, char* argv[]) -> int {
computations_us
=
std
::
stoi
(
argv
[
2
]);
computations_us
=
std
::
stoi
(
argv
[
2
]);
}
}
std
::
cout
<<
"Echoserver listening on "
<<
host
<<
":"
<<
port
<<
std
::
endl
;
if
(
argc
>
3
)
{
max_computations_us
=
std
::
stoi
(
argv
[
3
]);
if
(
max_computations_us
<
computations_us
)
DIE_MSG
(
"max_computations_us must be bigger than computations_us"
);
}
std
::
cout
<<
"Echoserver listening on "
<<
host
<<
":"
<<
port
;
if
(
computations_us
)
{
std
::
cout
<<
" with "
<<
computations_us
;
if
(
max_computations_us
)
std
::
cout
<<
" - "
<<
max_computations_us
;
std
::
cout
<<
" us computations"
;
}
std
::
cout
<<
std
::
endl
;
Runtime
runtime
;
Runtime
runtime
;
auto
serverFunc
=
[](
int
socket
)
{
auto
serverFunc
=
[](
int
socket
)
{
...
@@ -68,12 +83,20 @@ auto main(int argc, char* argv[]) -> int {
...
@@ -68,12 +83,20 @@ auto main(int argc, char* argv[]) -> int {
break
;
break
;
}
}
const
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
if
(
computations_us
)
{
const
auto
deadline
=
start
+
std
::
chrono
::
microseconds
(
computations_us
);
unsigned
int
computation
=
computations_us
;
// TODO: The suppressed linter error below may be a false positive
if
(
max_computations_us
)
{
// reported by clang-tidy.
// Worker::rand is always positiv. Why does it return int?
// NOLINTNEXTLINE(modernize-use-nullptr)
computation
+=
Worker
::
rand
()
%
(
max_computations_us
-
computations_us
);
while
(
std
::
chrono
::
steady_clock
::
now
()
<
deadline
)
{
}
const
auto
start
=
std
::
chrono
::
steady_clock
::
now
();
const
auto
deadline
=
start
+
std
::
chrono
::
microseconds
(
computation
);
// TODO: The suppressed linter error below may be a false positive
// reported by clang-tidy.
// NOLINTNEXTLINE(modernize-use-nullptr)
while
(
std
::
chrono
::
steady_clock
::
now
()
<
deadline
)
{
}
}
}
ssize_t
bytes_send
=
emper
::
io
::
sendAndWait
(
socket
,
buf
,
bytes_recv
,
MSG_NOSIGNAL
,
true
);
ssize_t
bytes_send
=
emper
::
io
::
sendAndWait
(
socket
,
buf
,
bytes_recv
,
MSG_NOSIGNAL
,
true
);
...
...
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