Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jochen Bauer
spn-relayserver
Commits
16ef5861
Commit
16ef5861
authored
Apr 12, 2018
by
Hubert Denkmair
Browse files
use ntohl(), vector as receive buf
parent
1c087a1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
relayserver/TcpProtocol.cpp
View file @
16ef5861
...
...
@@ -12,7 +12,7 @@ void TcpProtocol::SetMessageReceivedCallback(TcpProtocol::MessageReceivedCallbac
bool
TcpProtocol
::
Read
(
int
socket
)
{
std
::
array
<
char
,
1024
>
readbuf
;
std
::
array
<
char
,
8192
>
readbuf
;
ssize_t
bytesRead
=
read
(
socket
,
readbuf
.
data
(),
readbuf
.
size
());
if
(
bytesRead
<=
0
)
{
return
false
;
}
_buf
.
insert
(
_buf
.
end
(),
&
readbuf
[
0
],
&
readbuf
[
static_cast
<
size_t
>
(
bytesRead
)]);
...
...
@@ -21,10 +21,7 @@ bool TcpProtocol::Read(int socket)
{
if
((
_awaitedSize
==
0
)
&&
(
_buf
.
size
()
>=
4
))
{
_awaitedSize
=
static_cast
<
uint8_t
>
(
_buf
[
0
])
<<
24
|
static_cast
<
uint8_t
>
(
_buf
[
1
])
<<
16
|
static_cast
<
uint8_t
>
(
_buf
[
2
])
<<
8
|
static_cast
<
uint8_t
>
(
_buf
[
3
])
<<
0
;
_awaitedSize
=
ntohl
(
*
(
reinterpret_cast
<
uint32_t
*>
(
&
_buf
[
0
])));
_buf
.
erase
(
_buf
.
begin
(),
_buf
.
begin
()
+
4
);
}
else
if
((
_awaitedSize
>
0
)
&&
(
_buf
.
size
()
>=
_awaitedSize
))
...
...
relayserver/TcpProtocol.h
View file @
16ef5861
...
...
@@ -2,7 +2,6 @@
#include
<stddef.h>
#include
<stdint.h>
#include
<functional>
#include
<deque>
#include
<vector>
#include
<memory>
#include
"SpatialMap.h"
...
...
@@ -30,7 +29,7 @@ class TcpProtocol
size_t
_awaitedSize
=
0
;
std
::
deque
<
char
>
_buf
;
std
::
vector
<
char
>
_buf
;
MessageReceivedCallback
_messageReceivedCallback
;
std
::
unique_ptr
<
FoodMap
>
_food
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment