Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
99cb9d26
Commit
99cb9d26
authored
Dec 27, 2010
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Забыл добавить UDPPacket
parent
5ac52d97
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
0 deletions
+114
-0
UDPPacket.cc
extensions/UNet2/UDPPacket.cc
+45
-0
UDPPacket.h
extensions/UNet2/UDPPacket.h
+69
-0
No files found.
extensions/UNet2/UDPPacket.cc
0 → 100644
View file @
99cb9d26
#include "UDPPacket.h"
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
UniSetUDP
;
// -----------------------------------------------------------------------------
std
::
ostream
&
UniSetUDP
::
operator
<<
(
std
::
ostream
&
os
,
UniSetUDP
::
UDPHeader
&
p
)
{
return
os
<<
"nodeID="
<<
p
.
nodeID
<<
" procID="
<<
p
.
procID
<<
" dcount="
<<
p
.
dcount
<<
" pnum="
<<
p
.
num
;
}
// -----------------------------------------------------------------------------
std
::
ostream
&
UniSetUDP
::
operator
<<
(
std
::
ostream
&
os
,
UniSetUDP
::
UDPData
&
p
)
{
return
os
<<
"id="
<<
p
.
id
<<
" val="
<<
p
.
val
;
}
// -----------------------------------------------------------------------------
std
::
ostream
&
UniSetUDP
::
operator
<<
(
std
::
ostream
&
os
,
UniSetUDP
::
UDPMessage
&
p
)
{
return
os
;
}
// -----------------------------------------------------------------------------
UDPMessage
::
UDPMessage
()
:
count
(
0
)
{
}
// -----------------------------------------------------------------------------
bool
UDPMessage
::
addData
(
const
UniSetUDP
::
UDPData
&
dat
)
{
if
(
count
>=
MaxDataCount
)
return
false
;
msg
.
dat
[
count
]
=
dat
;
count
++
;
msg
.
header
.
dcount
=
count
;
return
true
;
}
// -----------------------------------------------------------------------------
bool
UDPMessage
::
addData
(
long
id
,
long
val
)
{
UDPData
d
(
id
,
val
);
return
addData
(
d
);
}
// -----------------------------------------------------------------------------
extensions/UNet2/UDPPacket.h
0 → 100644
View file @
99cb9d26
// $Id: UDPPacket.h,v 1.1 2009/02/10 20:38:27 vpashka Exp $
// -----------------------------------------------------------------------------
#ifndef UDPPacket_H_
#define UDPPacket_H_
// -----------------------------------------------------------------------------
#include <list>
#include <limits>
#include <ostream>
#include "UniSetTypes.h"
// -----------------------------------------------------------------------------
namespace
UniSetUDP
{
struct
UDPHeader
{
UDPHeader
()
:
num
(
0
),
nodeID
(
0
),
procID
(
0
),
dcount
(
0
){}
unsigned
long
num
;
long
nodeID
;
long
procID
;
size_t
dcount
;
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
UDPHeader
&
p
);
}
__attribute__
((
packed
));
static
unsigned
long
MaxPacketNum
=
std
::
numeric_limits
<
unsigned
long
>::
max
();
struct
UDPData
{
UDPData
()
:
id
(
UniSetTypes
::
DefaultObjectId
),
val
(
0
){}
UDPData
(
long
id
,
long
val
)
:
id
(
id
),
val
(
val
){}
long
id
;
long
val
;
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
UDPData
&
p
);
}
__attribute__
((
packed
));
static
const
int
MaxDataLen
=
8192
;
static
const
int
MaxDataCount
=
(
MaxDataLen
-
sizeof
(
UniSetUDP
::
UDPHeader
)
)
/
sizeof
(
UDPData
);
struct
DataPacket
{
UDPHeader
header
;
UDPData
dat
[
MaxDataCount
];
}
__attribute__
((
packed
));
struct
UDPMessage
:
public
UDPHeader
{
UDPMessage
();
bool
addData
(
const
UDPData
&
dat
);
bool
addData
(
long
id
,
long
val
);
inline
bool
isFull
(){
return
count
<
MaxDataCount
;
}
inline
int
size
(){
return
count
;
}
inline
int
byte_size
(){
return
count
*
sizeof
(
UDPData
);
}
DataPacket
msg
;
int
count
;
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
UDPMessage
&
p
);
};
}
// -----------------------------------------------------------------------------
#endif // UDPPacket_H_
// -----------------------------------------------------------------------------
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