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
318d55fd
Commit
318d55fd
authored
Apr 18, 2012
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue LIBZMQ-358
parent
36e9c4ac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
50 deletions
+24
-50
device.cpp
src/device.cpp
+24
-50
No files found.
src/device.cpp
View file @
318d55fd
...
...
@@ -32,89 +32,63 @@ int zmq::device (class socket_base_t *insocket_,
{
msg_t
msg
;
int
rc
=
msg
.
init
();
if
(
rc
!=
0
)
{
if
(
rc
!=
0
)
return
-
1
;
}
int64_t
more
;
// The algorithm below assumes ratio of request and replies processed
// under full load to be 1:1.
int
more
;
size_t
moresz
;
zmq_pollitem_t
items
[
2
];
items
[
0
].
socket
=
insocket_
;
items
[
0
].
fd
=
0
;
items
[
0
].
events
=
ZMQ_POLLIN
;
items
[
0
].
revents
=
0
;
items
[
1
].
socket
=
outsocket_
;
items
[
1
].
fd
=
0
;
items
[
1
].
events
=
ZMQ_POLLIN
;
items
[
1
].
revents
=
0
;
zmq_pollitem_t
items
[]
=
{
{
insocket_
,
0
,
ZMQ_POLLIN
,
0
},
{
outsocket_
,
0
,
ZMQ_POLLIN
,
0
}
};
while
(
true
)
{
// Wait while there are either requests or replies to process.
rc
=
zmq_poll
(
&
items
[
0
],
2
,
-
1
);
if
(
unlikely
(
rc
<
0
))
{
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
// The algorithm below asumes ratio of request and replies processed
// under full load to be 1:1. Although processing requests replies
// first is tempting it is suspectible to DoS attacks (overloading
// the system with unsolicited replies).
// Process a request.
if
(
items
[
0
].
revents
&
ZMQ_POLLIN
)
{
while
(
true
)
{
rc
=
insocket_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
{
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
moresz
=
sizeof
(
more
);
rc
=
insocket_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
if
(
unlikely
(
rc
<
0
))
{
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
rc
=
outsocket_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
{
rc
=
outsocket_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
if
(
!
more
)
if
(
more
==
0
)
break
;
}
}
// Process a reply.
if
(
items
[
1
].
revents
&
ZMQ_POLLIN
)
{
while
(
true
)
{
rc
=
outsocket_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
{
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
moresz
=
sizeof
(
more
);
rc
=
outsocket_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
if
(
unlikely
(
rc
<
0
))
{
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
rc
=
insocket_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
{
rc
=
insocket_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
if
(
!
more
)
if
(
more
==
0
)
break
;
}
}
}
return
0
;
}
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