Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
16011071
Commit
16011071
authored
Nov 18, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switched the bsp tools from using stringstream to vectorstream for
serialization.
parent
bdd3e221
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
23 deletions
+32
-23
bsp.cpp
dlib/bsp/bsp.cpp
+11
-13
bsp.h
dlib/bsp/bsp.h
+21
-10
No files found.
dlib/bsp/bsp.cpp
View file @
16011071
...
...
@@ -149,7 +149,7 @@ namespace dlib
if
(
msg
.
msg_type
==
MESSAGE_HEADER
)
{
msg
.
data
.
reset
(
new
std
::
string
);
msg
.
data
.
reset
(
new
std
::
vector
<
char
>
);
deserialize
(
msg
.
epoch
,
con
->
stream
);
deserialize
(
*
msg
.
data
,
con
->
stream
);
}
...
...
@@ -162,34 +162,32 @@ namespace dlib
}
catch
(
std
::
exception
&
e
)
{
std
::
ostringstream
sout
;
impl1
::
msg_data
msg
;
msg
.
data
.
reset
(
new
std
::
vector
<
char
>
);
vectorstream
sout
(
*
msg
.
data
);
sout
<<
"An exception was thrown while attempting to receive a message from processing node "
<<
sender_id
<<
".
\n
"
;
sout
<<
" Sending processing node address: "
<<
con
->
con
->
get_foreign_ip
()
<<
":"
<<
con
->
con
->
get_foreign_port
()
<<
std
::
endl
;
sout
<<
" Receiving processing node address: "
<<
con
->
con
->
get_local_ip
()
<<
":"
<<
con
->
con
->
get_local_port
()
<<
std
::
endl
;
sout
<<
" Receiving processing node id: "
<<
node_id
<<
std
::
endl
;
sout
<<
" Error message in the exception: "
<<
e
.
what
()
<<
std
::
endl
;
impl1
::
msg_data
msg
;
msg
.
sender_id
=
sender_id
;
msg
.
msg_type
=
READ_ERROR
;
msg
.
data
.
reset
(
new
std
::
string
);
*
msg
.
data
=
sout
.
str
();
msg_buffer
.
push_and_consume
(
msg
);
}
catch
(...)
{
std
::
ostringstream
sout
;
impl1
::
msg_data
msg
;
msg
.
data
.
reset
(
new
std
::
vector
<
char
>
);
vectorstream
sout
(
*
msg
.
data
);
sout
<<
"An exception was thrown while attempting to receive a message from processing node "
<<
sender_id
<<
".
\n
"
;
sout
<<
" Sending processing node address: "
<<
con
->
con
->
get_foreign_ip
()
<<
":"
<<
con
->
con
->
get_foreign_port
()
<<
std
::
endl
;
sout
<<
" Receiving processing node address: "
<<
con
->
con
->
get_local_ip
()
<<
":"
<<
con
->
con
->
get_local_port
()
<<
std
::
endl
;
sout
<<
" Receiving processing node id: "
<<
node_id
<<
std
::
endl
;
impl1
::
msg_data
msg
;
msg
.
sender_id
=
sender_id
;
msg
.
msg_type
=
READ_ERROR
;
msg
.
data
.
reset
(
new
std
::
string
);
*
msg
.
data
=
sout
.
str
();
msg_buffer
.
push_and_consume
(
msg
);
}
...
...
@@ -241,7 +239,7 @@ namespace dlib
}
else
if
(
msg
.
msg_type
==
impl2
::
READ_ERROR
)
{
throw
dlib
::
socket_error
(
*
msg
.
data
);
throw
dlib
::
socket_error
(
msg
.
data_to_string
()
);
}
else
if
(
msg
.
msg_type
==
impl2
::
MESSAGE_HEADER
)
{
...
...
@@ -332,7 +330,7 @@ namespace dlib
bool
bsp_context
::
receive_data
(
shared_ptr
<
std
::
string
>&
item
,
shared_ptr
<
std
::
vector
<
char
>
>&
item
,
unsigned
long
&
sending_node_id
)
{
...
...
@@ -406,7 +404,7 @@ namespace dlib
}
break
;
case
impl2
:
:
READ_ERROR
:
{
throw
dlib
::
socket_error
(
*
data
.
data
);
throw
dlib
::
socket_error
(
data
.
data_to_string
()
);
}
break
;
default
:
{
...
...
@@ -473,7 +471,7 @@ namespace dlib
void
bsp_context
::
send_data
(
const
std
::
string
&
item
,
const
std
::
vector
<
char
>
&
item
,
unsigned
long
target_node_id
)
{
...
...
dlib/bsp/bsp.h
View file @
16011071
...
...
@@ -12,6 +12,7 @@
#include "../serialize.h"
#include "../map.h"
#include "../ref.h"
#include "../vectorstream.h"
#include <queue>
#include <vector>
...
...
@@ -206,12 +207,20 @@ namespace dlib
struct
msg_data
{
shared_ptr
<
std
::
string
>
data
;
shared_ptr
<
std
::
vector
<
char
>
>
data
;
unsigned
long
sender_id
;
char
msg_type
;
dlib
::
uint64
epoch
;
msg_data
()
:
sender_id
(
0xFFFFFFFF
),
msg_type
(
-
1
),
epoch
(
0
)
{}
std
::
string
data_to_string
()
const
{
if
(
data
&&
data
->
size
()
!=
0
)
return
std
::
string
(
&
(
*
data
)[
0
],
data
->
size
());
else
return
""
;
}
};
// ------------------------------------------------------------------------------------
...
...
@@ -377,9 +386,10 @@ namespace dlib
<<
"
\n\t
this: "
<<
this
);
std
::
ostringstream
sout
;
std
::
vector
<
char
>
buf
;
vectorstream
sout
(
buf
);
serialize
(
item
,
sout
);
send_data
(
sout
.
str
()
,
target_node_id
);
send_data
(
buf
,
target_node_id
);
}
template
<
typename
T
>
...
...
@@ -387,7 +397,8 @@ namespace dlib
const
T
&
item
)
{
std
::
ostringstream
sout
;
std
::
vector
<
char
>
buf
;
vectorstream
sout
(
buf
);
serialize
(
item
,
sout
);
for
(
unsigned
long
i
=
0
;
i
<
number_of_nodes
();
++
i
)
{
...
...
@@ -395,7 +406,7 @@ namespace dlib
if
(
i
==
node_id
())
continue
;
send_data
(
sout
.
str
()
,
i
);
send_data
(
buf
,
i
);
}
}
...
...
@@ -409,7 +420,7 @@ namespace dlib
)
{
unsigned
long
id
;
shared_ptr
<
std
::
string
>
temp
;
shared_ptr
<
std
::
vector
<
char
>
>
temp
;
if
(
receive_data
(
temp
,
id
))
throw
dlib
::
socket_error
(
"Call to bsp_context::receive() got an unexpected message."
);
}
...
...
@@ -448,10 +459,10 @@ namespace dlib
unsigned
long
&
sending_node_id
)
{
shared_ptr
<
std
::
string
>
temp
;
shared_ptr
<
std
::
vector
<
char
>
>
temp
;
if
(
receive_data
(
temp
,
sending_node_id
))
{
std
::
istring
stream
sin
(
*
temp
);
vector
stream
sin
(
*
temp
);
deserialize
(
item
,
sin
);
if
(
sin
.
peek
()
!=
EOF
)
throw
serialization_error
(
"deserialize() did not consume all bytes produced by serialize(). "
...
...
@@ -485,7 +496,7 @@ namespace dlib
!*/
bool
receive_data
(
shared_ptr
<
std
::
string
>&
item
,
shared_ptr
<
std
::
vector
<
char
>
>&
item
,
unsigned
long
&
sending_node_id
);
...
...
@@ -499,7 +510,7 @@ namespace dlib
);
void
send_data
(
const
std
::
string
&
item
,
const
std
::
vector
<
char
>
&
item
,
unsigned
long
target_node_id
);
/*!
...
...
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