Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
2f854472
Commit
2f854472
authored
Jan 19, 2014
by
Ian Barber
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #839 from hintjens/master
Cleaned up option to force identity on outgoing connection
parents
5f07d103
50bd28c0
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
33 deletions
+41
-33
zmq.h
include/zmq.h
+2
-1
router.cpp
src/router.cpp
+21
-18
router.hpp
src/router.hpp
+2
-2
socket_base.hpp
src/socket_base.hpp
+3
-1
stream.cpp
src/stream.cpp
+11
-9
stream.hpp
src/stream.hpp
+2
-2
No files found.
include/zmq.h
View file @
2f854472
...
...
@@ -293,7 +293,8 @@ ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, int optval);
#define ZMQ_IPC_FILTER_PID 58
#define ZMQ_IPC_FILTER_UID 59
#define ZMQ_IPC_FILTER_GID 60
#define ZMQ_NEXT_CONNECT_PEER_ID 61
#define ZMQ_CONNECT_RID 61
/* Message options */
#define ZMQ_MORE 1
#define ZMQ_SRCFD 2
...
...
src/router.cpp
View file @
2f854472
...
...
@@ -31,7 +31,7 @@ zmq::router_t::router_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
more_in
(
false
),
current_out
(
NULL
),
more_out
(
false
),
next_
peer_
id
(
generate_random
()),
next_
r
id
(
generate_random
()),
mandatory
(
false
),
// raw_sock functionality in ROUTER is deprecated
raw_sock
(
false
),
...
...
@@ -88,9 +88,9 @@ int zmq::router_t::xsetsockopt (int option_, const void *optval_,
int
value
=
is_int
?
*
((
int
*
)
optval_
)
:
0
;
switch
(
option_
)
{
case
ZMQ_
NEXT_CONNECT_PEER_
ID
:
if
(
optval_
&&
optvallen_
)
{
next_identity
.
assign
((
char
*
)
optval_
,
optvallen_
);
case
ZMQ_
CONNECT_R
ID
:
if
(
optval_
&&
optvallen_
)
{
connect_rid
.
assign
((
char
*
)
optval_
,
optvallen_
);
return
0
;
}
break
;
...
...
@@ -387,33 +387,36 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
msg_t
msg
;
blob_t
identity
;
bool
ok
;
bool
next_identity
_used
=
false
;
bool
connect_rid
_used
=
false
;
if
(
next_identity
.
length
())
{
identity
=
blob_t
((
unsigned
char
*
)
next_identity
.
c_str
(),
next_identity
.
length
());
next_identity
.
clear
();
next_identity
_used
=
true
;
if
(
connect_rid
.
length
())
{
identity
=
blob_t
((
unsigned
char
*
)
connect_rid
.
c_str
(),
connect_rid
.
length
());
connect_rid
.
clear
();
connect_rid
_used
=
true
;
}
else
if
(
options
.
raw_sock
)
{
// Always assign identity for raw-socket
else
if
(
options
.
raw_sock
)
{
// Always assign identity for raw-socket
unsigned
char
buf
[
5
];
buf
[
0
]
=
0
;
put_uint32
(
buf
+
1
,
next_
peer_
id
++
);
put_uint32
(
buf
+
1
,
next_
r
id
++
);
identity
=
blob_t
(
buf
,
sizeof
buf
);
}
if
(
!
options
.
raw_sock
){
// pick up handshake cases and also case where next identity is set
if
(
!
options
.
raw_sock
)
{
// Pick up handshake cases and also case where next identity is set
msg
.
init
();
ok
=
pipe_
->
read
(
&
msg
);
if
(
!
ok
)
return
false
;
if
(
next_identity_used
){
// we read but do not use identity from peer
if
(
connect_rid_used
)
// we read but do not use identity from peer
msg
.
close
();
}
else
if
(
msg
.
size
()
==
0
)
{
else
if
(
msg
.
size
()
==
0
)
{
// Fall back on the auto-generation
unsigned
char
buf
[
5
];
buf
[
0
]
=
0
;
put_uint32
(
buf
+
1
,
next_
peer_
id
++
);
put_uint32
(
buf
+
1
,
next_
r
id
++
);
identity
=
blob_t
(
buf
,
sizeof
buf
);
msg
.
close
();
}
...
...
@@ -432,7 +435,7 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_)
// existing pipe so we can terminate it asynchronously.
unsigned
char
buf
[
5
];
buf
[
0
]
=
0
;
put_uint32
(
buf
+
1
,
next_
peer_
id
++
);
put_uint32
(
buf
+
1
,
next_
r
id
++
);
blob_t
new_identity
=
blob_t
(
buf
,
sizeof
buf
);
it
->
second
.
pipe
->
set_identity
(
new_identity
);
...
...
src/router.hpp
View file @
2f854472
...
...
@@ -104,9 +104,9 @@ namespace zmq
// If true, more outgoing message parts are expected.
bool
more_out
;
//
Peer ID
are generated. It's a simple increment and wrap-over
//
Routing IDs
are generated. It's a simple increment and wrap-over
// algorithm. This value is the next ID to use (if not used already).
uint32_t
next_
peer_
id
;
uint32_t
next_
r
id
;
// If true, report EAGAIN to the caller instead of silently dropping
// the message targeting an unknown peer.
...
...
src/socket_base.hpp
View file @
2f854472
...
...
@@ -164,8 +164,10 @@ namespace zmq
// Monitor socket cleanup
void
stop_monitor
();
// Next assigned name on a zmq_connect() call used by ROUTER and STREAM socket types
std
::
string
next_identity
;
std
::
string
connect_rid
;
private
:
// Creates new endpoint ID and adds the endpoint to the map.
void
add_endpoint
(
const
char
*
addr_
,
own_t
*
endpoint_
,
pipe_t
*
pipe
);
...
...
src/stream.cpp
View file @
2f854472
...
...
@@ -30,7 +30,7 @@ zmq::stream_t::stream_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
identity_sent
(
false
),
current_out
(
NULL
),
more_out
(
false
),
next_
peer_
id
(
generate_random
())
next_
r
id
(
generate_random
())
{
options
.
type
=
ZMQ_STREAM
;
options
.
raw_sock
=
true
;
...
...
@@ -163,13 +163,14 @@ int zmq::stream_t::xsend (msg_t *msg_)
return
0
;
}
int
zmq
::
stream_t
::
xsetsockopt
(
int
option_
,
const
void
*
optval_
,
size_t
optvallen_
)
{
switch
(
option_
)
{
case
ZMQ_NEXT_CONNECT_PEER_
ID
:
if
(
optval_
&&
optvallen_
)
{
next_identity
.
assign
((
char
*
)
optval_
,
optvallen_
);
case
ZMQ_CONNECT_R
ID
:
if
(
optval_
&&
optvallen_
)
{
connect_rid
.
assign
((
char
*
)
optval_
,
optvallen_
);
return
0
;
}
break
;
...
...
@@ -179,6 +180,7 @@ int zmq::stream_t::xsetsockopt (int option_, const void *optval_,
errno
=
EINVAL
;
return
-
1
;
}
int
zmq
::
stream_t
::
xrecv
(
msg_t
*
msg_
)
{
if
(
prefetched
)
{
...
...
@@ -260,13 +262,13 @@ void zmq::stream_t::identify_peer (pipe_t *pipe_)
unsigned
char
buffer
[
5
];
buffer
[
0
]
=
0
;
blob_t
identity
;
if
(
next_identity
.
length
())
{
identity
=
blob_t
((
unsigned
char
*
)
next_identity
.
c_str
(),
next_identity
.
length
());
next_identity
.
clear
();
if
(
connect_rid
.
length
())
{
identity
=
blob_t
((
unsigned
char
*
)
connect_rid
.
c_str
(),
connect_rid
.
length
());
connect_rid
.
clear
();
}
else
{
put_uint32
(
buffer
+
1
,
next_
peer_
id
++
);
put_uint32
(
buffer
+
1
,
next_
r
id
++
);
blob_t
identity
=
blob_t
(
buffer
,
sizeof
buffer
);
memcpy
(
options
.
identity
,
identity
.
data
(),
identity
.
size
());
options
.
identity_size
=
identity
.
size
();
...
...
src/stream.hpp
View file @
2f854472
...
...
@@ -84,9 +84,9 @@ namespace zmq
// If true, more outgoing message parts are expected.
bool
more_out
;
//
Peer ID
are generated. It's a simple increment and wrap-over
//
Routing IDs
are generated. It's a simple increment and wrap-over
// algorithm. This value is the next ID to use (if not used already).
uint32_t
next_
peer_
id
;
uint32_t
next_
r
id
;
stream_t
(
const
stream_t
&
);
const
stream_t
&
operator
=
(
const
stream_t
&
);
...
...
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