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
41b2f83b
Commit
41b2f83b
authored
Oct 21, 2013
by
Richard Newton
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #714 from hintjens/master
Cleaned up the code
parents
08c91c0f
406e6051
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
62 deletions
+68
-62
proxy.cpp
src/proxy.cpp
+68
-62
No files found.
src/proxy.cpp
View file @
41b2f83b
...
...
@@ -76,8 +76,15 @@ int zmq::proxy (
{
control_
,
0
,
ZMQ_POLLIN
,
0
}
};
int
qt_poll_items
=
(
control_
?
3
:
2
);
enum
{
suspend
,
resume
,
terminate
}
state
=
resume
;
while
(
state
!=
terminate
)
{
// Proxy can be in these three states
enum
{
active
,
paused
,
terminated
}
state
=
active
;
while
(
state
!=
terminated
)
{
// Wait while there are either requests or replies to process.
rc
=
zmq_poll
(
&
items
[
0
],
qt_poll_items
,
-
1
);
if
(
unlikely
(
rc
<
0
))
...
...
@@ -85,46 +92,45 @@ int zmq::proxy (
// Process a control command if any
if
(
control_
&&
items
[
2
].
revents
&
ZMQ_POLLIN
)
{
rc
=
control_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
moresz
=
sizeof
more
;
rc
=
control_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
if
(
unlikely
(
rc
<
0
)
||
more
)
return
-
1
;
// Copy message to capture socket if any
if
(
capture_
)
{
msg_t
ctrl
;
rc
=
ctrl
.
init
();
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
ctrl
.
copy
(
msg
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
capture_
->
send
(
&
ctrl
,
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
// process control command
int
size
=
msg
.
size
();
char
*
message
=
(
char
*
)
malloc
(
size
+
1
);
memcpy
(
message
,
msg
.
data
(),
size
);
message
[
size
]
=
'\0'
;
if
(
size
==
8
&&
!
memcmp
(
message
,
"SUSPEND"
,
8
))
state
=
suspend
;
else
if
(
size
==
7
&&
!
memcmp
(
message
,
"RESUME"
,
7
))
state
=
resume
;
else
if
(
size
==
10
&&
!
memcmp
(
message
,
"TERMINATE"
,
10
))
state
=
terminate
;
else
fprintf
(
stderr
,
"Warning :
\"
%s
\"
bad command received by proxy
\n
"
,
message
);
// prefered compared to "return -1"
free
(
message
);
rc
=
control_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
moresz
=
sizeof
more
;
rc
=
control_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
if
(
unlikely
(
rc
<
0
)
||
more
)
return
-
1
;
// Copy message to capture socket if any
if
(
capture_
)
{
msg_t
ctrl
;
rc
=
ctrl
.
init
();
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
ctrl
.
copy
(
msg
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
capture_
->
send
(
&
ctrl
,
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
if
(
msg
.
size
()
==
6
&&
memcmp
(
msg
.
data
(),
"PAUSE"
,
6
)
==
0
)
state
=
paused
;
else
if
(
msg
.
size
()
==
7
&&
memcmp
(
msg
.
data
(),
"RESUME"
,
7
)
==
0
)
state
=
active
;
else
if
(
msg
.
size
()
==
10
&&
memcmp
(
msg
.
data
(),
"TERMINATE"
,
10
)
==
0
)
state
=
terminated
;
else
{
// This is an API error, we should assert
puts
(
"E: invalid command sent to proxy"
);
assert
(
false
);
}
}
// Process a request
if
(
state
==
resume
&&
items
[
0
].
revents
&
ZMQ_POLLIN
)
{
if
(
state
==
active
&&
items
[
0
].
revents
&
ZMQ_POLLIN
)
{
while
(
true
)
{
rc
=
frontend_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
...
...
@@ -156,38 +162,38 @@ int zmq::proxy (
}
}
// Process a reply
if
(
state
==
resume
&&
items
[
1
].
revents
&
ZMQ_POLLIN
)
{
if
(
state
==
active
&&
items
[
1
].
revents
&
ZMQ_POLLIN
)
{
while
(
true
)
{
rc
=
backend_
->
recv
(
&
msg
,
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
moresz
=
sizeof
more
;
rc
=
backend_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
// Copy message to capture socket if any
if
(
capture_
)
{
msg_t
ctrl
;
rc
=
ctrl
.
init
();
if
(
unlikely
(
rc
<
0
))
return
-
1
;
moresz
=
sizeof
more
;
rc
=
backend_
->
getsockopt
(
ZMQ_RCVMORE
,
&
more
,
&
moresz
);
rc
=
ctrl
.
copy
(
msg
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
// Copy message to capture socket if any
if
(
capture_
)
{
msg_t
ctrl
;
rc
=
ctrl
.
init
();
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
ctrl
.
copy
(
msg
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
rc
=
capture_
->
send
(
&
ctrl
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
}
rc
=
frontend_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
rc
=
capture_
->
send
(
&
ctrl
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
if
(
more
==
0
)
break
;
}
rc
=
frontend_
->
send
(
&
msg
,
more
?
ZMQ_SNDMORE
:
0
);
if
(
unlikely
(
rc
<
0
))
return
-
1
;
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