Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
e4adf991
Commit
e4adf991
authored
Oct 24, 2012
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle and log exceptions correctly in default_peer
parent
69913604
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
32 deletions
+40
-32
src/binary_deserializer.cpp
src/binary_deserializer.cpp
+28
-27
src/default_peer.cpp
src/default_peer.cpp
+7
-1
src/default_protocol.cpp
src/default_protocol.cpp
+2
-2
src/ipv4_io_stream.cpp
src/ipv4_io_stream.cpp
+2
-1
unit_testing/test__remote_actor.cpp
unit_testing/test__remote_actor.cpp
+1
-1
No files found.
src/binary_deserializer.cpp
View file @
e4adf991
...
...
@@ -33,13 +33,15 @@
#include <cstring>
#include <sstream>
#include <iterator>
#include <iostream>
#include <exception>
#include <stdexcept>
#include <type_traits>
#include "cppa/detail/logging.hpp"
#include "cppa/binary_deserializer.hpp"
using
std
::
enable_if
;
using
namespace
std
;
namespace
cppa
{
...
...
@@ -49,32 +51,33 @@ typedef const char* iterator;
inline
void
range_check
(
iterator
begin
,
iterator
end
,
size_t
read_size
)
{
if
((
begin
+
read_size
)
>
end
)
{
throw
std
::
out_of_range
(
"binary_deserializer::read()"
);
CPPA_LOGF_ERROR
(
"range_check failed"
);
throw
out_of_range
(
"binary_deserializer::read()"
);
}
}
template
<
typename
T
>
iterator
read
(
iterator
begin
,
iterator
end
,
T
&
storage
,
typename
enable_if
<
std
::
is_integral
<
T
>::
value
>::
type
*
=
0
)
{
typename
enable_if
<
is_integral
<
T
>::
value
>::
type
*
=
0
)
{
range_check
(
begin
,
end
,
sizeof
(
T
));
memcpy
(
&
storage
,
begin
,
sizeof
(
T
));
return
begin
+
sizeof
(
T
);
}
iterator
read
(
iterator
begin
,
iterator
end
,
st
d
::
st
ring
&
storage
)
{
std
::
uint32_t
str_size
;
iterator
read
(
iterator
begin
,
iterator
end
,
string
&
storage
)
{
uint32_t
str_size
;
begin
=
read
(
begin
,
end
,
str_size
);
range_check
(
begin
,
end
,
str_size
);
storage
.
clear
();
storage
.
reserve
(
str_size
);
iterator
cpy_end
=
begin
+
str_size
;
std
::
copy
(
begin
,
cpy_end
,
std
::
back_inserter
(
storage
));
copy
(
begin
,
cpy_end
,
back_inserter
(
storage
));
return
begin
+
str_size
;
}
template
<
typename
CharType
,
typename
StringType
>
iterator
read_unicode_string
(
iterator
begin
,
iterator
end
,
StringType
&
str
)
{
std
::
uint32_t
str_size
;
uint32_t
str_size
;
begin
=
read
(
begin
,
end
,
str_size
);
str
.
reserve
(
str_size
);
for
(
size_t
i
=
0
;
i
<
str_size
;
++
i
)
{
...
...
@@ -88,25 +91,25 @@ iterator read_unicode_string(iterator begin, iterator end, StringType& str) {
// @returns the next iterator position
template
<
typename
T
>
iterator
read
(
iterator
begin
,
iterator
end
,
T
&
value
,
typename
enable_if
<
std
::
is_floating_point
<
T
>::
value
>::
type
*
=
0
)
{
typename
enable_if
<
is_floating_point
<
T
>::
value
>::
type
*
=
0
)
{
// floating points are written as strings
st
d
::
st
ring
str
;
string
str
;
auto
result
=
read_unicode_string
<
char
>
(
begin
,
end
,
str
);
std
::
istringstream
iss
(
str
);
istringstream
iss
(
str
);
iss
>>
value
;
return
result
;
}
iterator
read
(
iterator
begin
,
iterator
end
,
std
::
u16string
&
storage
)
{
iterator
read
(
iterator
begin
,
iterator
end
,
u16string
&
storage
)
{
// char16_t is guaranteed to has *at least* 16 bytes,
// but not to have *exactly* 16 bytes; thus use uint16_t
return
read_unicode_string
<
std
::
uint16_t
>
(
begin
,
end
,
storage
);
return
read_unicode_string
<
uint16_t
>
(
begin
,
end
,
storage
);
}
iterator
read
(
iterator
begin
,
iterator
end
,
std
::
u32string
&
storage
)
{
iterator
read
(
iterator
begin
,
iterator
end
,
u32string
&
storage
)
{
// char32_t is guaranteed to has *at least* 32 bytes,
// but not to have *exactly* 32 bytes; thus use uint32_t
return
read_unicode_string
<
std
::
uint32_t
>
(
begin
,
end
,
storage
);
return
read_unicode_string
<
uint32_t
>
(
begin
,
end
,
storage
);
}
struct
pt_reader
{
...
...
@@ -133,34 +136,32 @@ binary_deserializer::binary_deserializer(const char* bbegin, const char* bend,
actor_addressing
*
addressing
)
:
super
(
addressing
),
pos
(
bbegin
),
end
(
bend
)
{
}
st
d
::
st
ring
binary_deserializer
::
seek_object
()
{
st
d
::
st
ring
result
;
string
binary_deserializer
::
seek_object
()
{
string
result
;
pos
=
read
(
pos
,
end
,
result
);
return
result
;
}
st
d
::
st
ring
binary_deserializer
::
peek_object
()
{
st
d
::
st
ring
result
;
string
binary_deserializer
::
peek_object
()
{
string
result
;
read
(
pos
,
end
,
result
);
return
result
;
}
void
binary_deserializer
::
begin_object
(
const
std
::
string
&
)
{
}
void
binary_deserializer
::
begin_object
(
const
string
&
)
{
}
void
binary_deserializer
::
end_object
()
{
}
void
binary_deserializer
::
end_object
()
{
}
size_t
binary_deserializer
::
begin_sequence
()
{
static_assert
(
sizeof
(
size_t
)
>=
sizeof
(
std
::
uint32_t
),
CPPA_LOG_TRACE
(
""
);
static_assert
(
sizeof
(
size_t
)
>=
sizeof
(
uint32_t
),
"sizeof(size_t) < sizeof(uint32_t)"
);
std
::
uint32_t
result
;
uint32_t
result
;
pos
=
read
(
pos
,
end
,
result
);
return
static_cast
<
size_t
>
(
result
);
}
void
binary_deserializer
::
end_sequence
()
{
}
void
binary_deserializer
::
end_sequence
()
{
}
primitive_variant
binary_deserializer
::
read_value
(
primitive_type
ptype
)
{
primitive_variant
val
(
ptype
);
...
...
@@ -174,7 +175,7 @@ void binary_deserializer::read_tuple(size_t size,
const
primitive_type
*
ptypes
,
primitive_variant
*
storage
)
{
for
(
auto
end
=
ptypes
+
size
;
ptypes
!=
end
;
++
ptypes
)
{
*
storage
=
std
::
move
(
read_value
(
*
ptypes
));
*
storage
=
move
(
read_value
(
*
ptypes
));
++
storage
;
}
}
...
...
src/default_peer.cpp
View file @
e4adf991
...
...
@@ -135,7 +135,13 @@ continue_reading_result default_peer::continue_reading() {
addressed_message
msg
;
binary_deserializer
bd
(
m_rd_buf
.
data
(),
m_rd_buf
.
size
(),
m_parent
->
addressing
());
m_meta_msg
->
deserialize
(
&
msg
,
&
bd
);
try
{
m_meta_msg
->
deserialize
(
&
msg
,
&
bd
);
}
catch
(
exception
&
e
)
{
CPPA_LOG_ERROR
(
"exception during read_message: "
<<
detail
::
demangle
(
typeid
(
e
))
<<
", what(): "
<<
e
.
what
());
return
read_failure
;
}
auto
&
content
=
msg
.
content
();
CPPA_LOG_DEBUG
(
"deserialized: "
<<
to_string
(
msg
));
//DEBUG("<-- " << to_string(msg));
...
...
src/default_protocol.cpp
View file @
e4adf991
...
...
@@ -155,10 +155,10 @@ actor_ptr default_protocol::remote_actor(io_stream_ptr_pair io,
// throws on error
io
.
second
->
write
(
&
process_id
,
sizeof
(
std
::
uint32_t
));
io
.
second
->
write
(
pinf
->
node_id
().
data
(),
pinf
->
node_id
().
size
());
std
::
uint32_t
remote_aid
;
actor_id
remote_aid
;
std
::
uint32_t
peer_pid
;
process_information
::
node_id_type
peer_node_id
;
io
.
first
->
read
(
&
remote_aid
,
sizeof
(
remote_a
id
));
io
.
first
->
read
(
&
remote_aid
,
sizeof
(
actor_
id
));
io
.
first
->
read
(
&
peer_pid
,
sizeof
(
std
::
uint32_t
));
io
.
first
->
read
(
peer_node_id
.
data
(),
peer_node_id
.
size
());
process_information_ptr
pinfptr
(
new
process_information
(
peer_pid
,
peer_node_id
));
...
...
src/ipv4_io_stream.cpp
View file @
e4adf991
...
...
@@ -121,7 +121,8 @@ network::io_stream_ptr ipv4_io_stream::from_native_socket(native_socket_type fd)
}
network
::
io_stream_ptr
ipv4_io_stream
::
connect_to
(
const
char
*
host
,
std
::
uint16_t
port
)
{
std
::
uint16_t
port
)
{
CPPA_LOG_INFO
(
"try to connect to "
<<
host
<<
" on port "
<<
port
);
struct
sockaddr_in
serv_addr
;
struct
hostent
*
server
;
native_socket_type
fd
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
...
...
unit_testing/test__remote_actor.cpp
View file @
e4adf991
...
...
@@ -218,7 +218,7 @@ int client_part(const vector<string_pair>& args) {
}
// namespace <anonymous>
void
verbose_terminate
()
{
try
{
if
(
std
::
uncaught_exception
())
;
throw
;
}
try
{
if
(
std
::
uncaught_exception
())
throw
;
}
catch
(
std
::
exception
&
e
)
{
cerr
<<
"terminate called after throwing "
<<
to_verbose_string
(
e
)
<<
endl
;
...
...
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