Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
5c8cffa3
Commit
5c8cffa3
authored
May 07, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the server print intervals between packet receptions
parent
fa4f28e6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
6 deletions
+36
-6
packet-exchange/src/client.c
packet-exchange/src/client.c
+7
-4
packet-exchange/src/server.c
packet-exchange/src/server.c
+29
-2
No files found.
packet-exchange/src/client.c
View file @
5c8cffa3
...
...
@@ -76,8 +76,8 @@ int main(int argc, char *argv[]) {
main_param_t
main_param
;
// Default values
param
.
interval
=
1
;
param
.
max_cycles
=
-
1
;
param
.
interval
=
1
00000
*
1000
;
param
.
max_cycles
=
0
;
param
.
priority
=
99
;
main_param
.
refresh_rate
=
50000
;
...
...
@@ -93,9 +93,12 @@ int main(int argc, char *argv[]) {
for
(;;)
{
usleep
(
main_param
.
refresh_rate
);
#ifdef DEBUG_ENABLE
printf
(
"Nb cycles: %d
\n
"
,
param
.
stats
.
nb_cycles
);
#endif
if
(
param
.
max_cycles
==
param
.
stats
.
nb_cycles
)
break
;
if
(
param
.
max_cycles
)
if
(
param
.
max_cycles
==
param
.
stats
.
nb_cycles
)
break
;
}
exit
(
EXIT_SUCCESS
);
...
...
packet-exchange/src/server.c
View file @
5c8cffa3
...
...
@@ -2,16 +2,24 @@
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#define NSEC_PER_SEC UINT64_C(1000000000)
#define SERVER_PORT "50000"
#define BUFFER_SIZE 1024
static
inline
uint64_t
calcdiff_ns
(
struct
timespec
t1
,
struct
timespec
t2
);
static
inline
uint64_t
max
(
uint64_t
a
,
uint64_t
b
);
static
inline
uint64_t
min
(
uint64_t
a
,
uint64_t
b
);
static
void
*
get_in_addr
(
struct
sockaddr
*
sa
)
{
if
(
sa
->
sa_family
==
AF_INET
)
return
&
(((
struct
sockaddr_in
*
)
sa
)
->
sin_addr
);
return
&
(((
struct
sockaddr_in6
*
)
sa
)
->
sin6_addr
);
...
...
@@ -19,6 +27,9 @@ static void *get_in_addr(struct sockaddr *sa) {
int
main
()
{
int
status
;
struct
timespec
current
,
previous
;
uint64_t
diff
;
int
sockfd
=
0
;
struct
addrinfo
hints
,
*
servinfo
,
*
servinfo_it
;
...
...
@@ -72,17 +83,33 @@ int main() {
printf
(
"recvfrom error
\n
"
);
return
2
;
}
clock_gettime
(
CLOCK_MONOTONIC
,
&
current
);
inet_ntop
(
client_addr
.
ss_family
,
get_in_addr
((
struct
sockaddr
*
)
&
client_addr
),
client_addr_str
,
sizeof
(
client_addr_str
));
buf
[
bytes_received
]
=
'\0'
;
printf
(
"got packet from %s: %s (%d long)
\n
"
,
client_addr_str
,
buf
,
bytes_received
);
diff
=
calcdiff_ns
(
current
,
previous
);
printf
(
"%ld: got packet from %s: %s (%d long)
\n
"
,
diff
,
client_addr_str
,
buf
,
bytes_received
);
previous
=
current
;
}
close
(
sockfd
);
return
0
;
}
static
inline
uint64_t
calcdiff_ns
(
struct
timespec
t1
,
struct
timespec
t2
)
{
uint64_t
diff
;
diff
=
NSEC_PER_SEC
*
(
uint64_t
)((
int
)
t1
.
tv_sec
-
(
int
)
t2
.
tv_sec
);
diff
+=
((
int
)
t1
.
tv_nsec
-
(
int
)
t2
.
tv_nsec
);
return
diff
;
}
static
inline
uint64_t
max
(
uint64_t
a
,
uint64_t
b
)
{
return
a
>
b
?
a
:
b
;
}
static
inline
uint64_t
min
(
uint64_t
a
,
uint64_t
b
)
{
return
a
<
b
?
a
:
b
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment