Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
PRRT
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
37
Issues
37
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LARN
PRRT
Commits
223addb1
Commit
223addb1
authored
Aug 27, 2018
by
Andreas Schmidt
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Packet copies are now shallow copies by default
parent
fff6c3e9
Pipeline
#2904
passed with stages
in 1 minute and 26 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
4 deletions
+49
-4
prrt/CMakeLists.txt
prrt/CMakeLists.txt
+2
-0
prrt/proto/types/packet.c
prrt/proto/types/packet.c
+22
-4
prrt/proto/types/packet.h
prrt/proto/types/packet.h
+6
-0
prrt/refcount.c
prrt/refcount.c
+19
-0
No files found.
prrt/CMakeLists.txt
View file @
223addb1
...
...
@@ -16,6 +16,8 @@ add_subdirectory(util)
add_executable
(
sender sender.c
)
add_executable
(
receiver receiver.c
)
add_executable
(
refcount refcount.c
)
target_link_libraries
(
sender LINK_PUBLIC PRRT UTIL
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
receiver LINK_PUBLIC PRRT UTIL
${
CMAKE_THREAD_LIBS_INIT
}
)
target_link_libraries
(
refcount LINK_PUBLIC PRRT UTIL
${
CMAKE_THREAD_LIBS_INIT
}
)
prrt/proto/types/packet.c
View file @
223addb1
...
...
@@ -92,6 +92,11 @@ int PrrtPacket_print(PrrtPacket *packet_ptr) {
}
PrrtPacket
*
PrrtPacket_copy
(
PrrtPacket
*
original
)
{
__sync_fetch_and_add
(
&
original
->
refcount
,
1
);
return
original
;
}
PrrtPacket
*
PrrtPacket_deepcopy
(
PrrtPacket
*
original
)
{
PrrtPacket
*
newPacket
=
calloc
(
1
,
sizeof
(
PrrtPacket
));
check_mem
(
newPacket
);
void
*
payload
=
calloc
(
1
,
original
->
payloadLength
);
...
...
@@ -105,6 +110,8 @@ PrrtPacket *PrrtPacket_copy(PrrtPacket *original) {
newPacket
->
sequenceNumber
=
original
->
sequenceNumber
;
newPacket
->
type_priority
=
original
->
type_priority
;
newPacket
->
refcount
=
1
;
return
newPacket
;
error:
...
...
@@ -122,6 +129,7 @@ create_header(uint8_t priority, prrtSequenceNumber_t seqno, prrtPacketLength_t s
packet
->
index
=
index
;
packet
->
sequenceNumber
=
seqno
;
packet
->
payloadLength
=
size
;
packet
->
refcount
=
1
;
return
packet
;
...
...
@@ -214,6 +222,10 @@ void *encode_general_header(void *buf_ptr, const PrrtPacket *packet) {
}
bool
PrrtPacket_decode
(
void
*
srcBuffer
,
uint16_t
srcBufferSize
,
PrrtPacket
*
targetPacket
)
{
// targetPacket is uninitialized, so we need to set the reference count
targetPacket
->
refcount
=
1
;
prrtPacketLength_t
payload_len
=
(
prrtPacketLength_t
)
(
srcBufferSize
-
PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH
);
targetPacket
->
type_priority
=
*
(
uint8_t
*
)
srcBuffer
;
srcBuffer
+=
1
;
...
...
@@ -295,11 +307,17 @@ void *decode_data_header(void *dstBuffer, const void *srcBuffer) {
}
int
PrrtPacket_destroy
(
PrrtPacket
*
packet
)
{
if
(
packet
->
payload
!=
NULL
)
{
free
(
packet
->
payload
);
prrtRefcount_t
refcount
=
__sync_fetch_and_sub
(
&
packet
->
refcount
,
1
);
if
(
refcount
>
1
)
{
return
0
;
}
else
{
if
(
packet
->
payload
!=
NULL
)
{
free
(
packet
->
payload
);
}
free
(
packet
);
return
0
;
}
free
(
packet
);
return
0
;
}
PrrtPacket
*
PrrtPacket_create_data_packet
(
uint8_t
priority
,
const
void
*
payloadPointer
,
...
...
prrt/proto/types/packet.h
View file @
223addb1
...
...
@@ -36,6 +36,8 @@ typedef atomic_uint_fast32_t prrtAtomicDeliveryRate_t;
typedef
uint32_t
prrtByteCount_t
;
typedef
uint8_t
prrtPacketType_t
;
typedef
uint16_t
prrtRefcount_t
;
typedef
struct
prrtIncompleteBlock
{
prrtSequenceNumber_t
sequenceNumberBase
;
uint16_t
repairCycleIndex
;
...
...
@@ -58,6 +60,8 @@ typedef struct prrtPacket {
prrtTimedelta_t
rtt
;
struct
sockaddr_in
sender_addr
;
prrtRefcount_t
refcount
;
}
PrrtPacket
;
#define PRRT_PACKET_GENERAL_HEADER_SIZE 8
#define PRRT_PACKET_ENCODED_GENERAL_HEADER_LENGTH 4
...
...
@@ -124,6 +128,8 @@ int PrrtPacket_print(PrrtPacket *packet_ptr);
PrrtPacket
*
PrrtPacket_copy
(
PrrtPacket
*
original
);
PrrtPacket
*
PrrtPacket_deepcopy
(
PrrtPacket
*
original
);
PrrtPacket
*
PrrtPacket_create_data_packet
(
uint8_t
priority
,
const
void
*
payloadPointer
,
prrtPacketLength_t
dataLength
,
prrtSequenceNumber_t
sequenceNumber
,
prrtTimedelta_t
targetDelay
);
...
...
prrt/refcount.c
0 → 100644
View file @
223addb1
#include "proto/types/packet.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const
int
prio
=
0
;
const
int
seqnum
=
1337
;
const
int
timedelta
=
0
;
int
main
()
{
const
char
*
payload
=
"just some example payload"
;
struct
prrtPacket
*
a
=
PrrtPacket_create_data_packet
(
prio
,
payload
,
strlen
(
payload
),
seqnum
,
timedelta
);
printf
(
"refcount(a): %u
\n\n
"
,
a
->
refcount
);
struct
prrtPacket
*
b
=
PrrtPacket_copy
(
a
);
printf
(
"refcount(a): %u
\n
refcount(b): %u
\n\n
"
,
a
->
refcount
,
b
->
refcount
);
PrrtPacket_destroy
(
a
);
printf
(
"refcount(b): %u
\n
"
,
b
->
refcount
);
PrrtPacket_destroy
(
b
);
}
Andreas Schmidt
@as
mentioned in issue
#25 (closed)
·
Aug 27, 2018
mentioned in issue
#25 (closed)
mentioned in issue #25
Toggle commit list
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