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
9d63ebf6
Commit
9d63ebf6
authored
May 28, 2013
by
Pieter Hintjens
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #564 from hurtonm/master
Rename pipe states so they are more mnemonic
parents
f781eb7e
4e4803e0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
50 deletions
+56
-50
pipe.cpp
src/pipe.cpp
+40
-36
pipe.hpp
src/pipe.hpp
+16
-14
No files found.
src/pipe.cpp
View file @
9d63ebf6
...
...
@@ -96,7 +96,9 @@ zmq::blob_t zmq::pipe_t::get_identity ()
bool
zmq
::
pipe_t
::
check_read
()
{
if
(
unlikely
(
!
in_active
||
(
state
!=
active
&&
state
!=
pending
)))
if
(
unlikely
(
!
in_active
))
return
false
;
if
(
unlikely
(
state
!=
active
&&
state
!=
waiting_for_delimiter
))
return
false
;
// Check if there's an item in the pipe.
...
...
@@ -120,7 +122,9 @@ bool zmq::pipe_t::check_read ()
bool
zmq
::
pipe_t
::
read
(
msg_t
*
msg_
)
{
if
(
unlikely
(
!
in_active
||
(
state
!=
active
&&
state
!=
pending
)))
if
(
unlikely
(
!
in_active
))
return
false
;
if
(
unlikely
(
state
!=
active
&&
state
!=
waiting_for_delimiter
))
return
false
;
if
(
!
inpipe
->
read
(
msg_
))
{
...
...
@@ -187,7 +191,7 @@ void zmq::pipe_t::rollback ()
void
zmq
::
pipe_t
::
flush
()
{
// The peer does not exist anymore at this point.
if
(
state
==
term
inating
)
if
(
state
==
term
_ack_sent
)
return
;
if
(
outpipe
&&
!
outpipe
->
flush
())
...
...
@@ -196,7 +200,7 @@ void zmq::pipe_t::flush ()
void
zmq
::
pipe_t
::
process_activate_read
()
{
if
(
!
in_active
&&
(
state
==
active
||
state
==
pending
))
{
if
(
!
in_active
&&
(
state
==
active
||
state
==
waiting_for_delimiter
))
{
in_active
=
true
;
sink
->
read_activated
(
this
);
}
...
...
@@ -240,24 +244,24 @@ void zmq::pipe_t::process_pipe_term ()
{
// This is the simple case of peer-induced termination. If there are no
// more pending messages to read, or if the pipe was configured to drop
// pending messages, we can move directly to the term
inating
state.
// Otherwise we'll hang up in
pending state till all the pending messages
//
are sent
.
// pending messages, we can move directly to the term
_ack_sent
state.
// Otherwise we'll hang up in
waiting_for_delimiter state till all
//
pending messages are read
.
if
(
state
==
active
)
{
if
(
!
delay
)
{
state
=
term
inating
;
state
=
term
_ack_sent
;
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
}
else
state
=
pending
;
state
=
waiting_for_delimiter
;
return
;
}
// Delimiter happened to arrive before the term command. Now we have the
// term command as well, so we can move straight to term
inating
state.
if
(
state
==
delimited
)
{
state
=
term
inating
;
// term command as well, so we can move straight to term
_ack_sent
state.
if
(
state
==
delimite
r_receive
d
)
{
state
=
term
_ack_sent
;
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
return
;
...
...
@@ -266,8 +270,8 @@ void zmq::pipe_t::process_pipe_term ()
// This is the case where both ends of the pipe are closed in parallel.
// We simply reply to the request by ack and continue waiting for our
// own ack.
if
(
state
==
term
inated
)
{
state
=
double_terminated
;
if
(
state
==
term
_req_sent1
)
{
state
=
term_req_sent2
;
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
return
;
...
...
@@ -283,16 +287,16 @@ void zmq::pipe_t::process_pipe_term_ack ()
zmq_assert
(
sink
);
sink
->
terminated
(
this
);
// In term
inating and double_terminated
states there's nothing to do.
// Simply deallocate the pipe. In term
inated state we have to ack the
//
peer before deallocating this side of the pipe. All the other states
// are invalid.
if
(
state
==
term
inated
)
{
// In term
_ack_sent and term_req_sent2
states there's nothing to do.
// Simply deallocate the pipe. In term
_req_sent1 state we have to ack
//
the peer before deallocating this side of the pipe.
//
All the other states
are invalid.
if
(
state
==
term
_req_sent1
)
{
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
}
else
zmq_assert
(
state
==
term
inating
||
state
==
double_terminated
);
zmq_assert
(
state
==
term
_ack_sent
||
state
==
term_req_sent2
);
// We'll deallocate the inbound pipe, the peer will deallocate the outbound
// pipe (which is an inbound pipe from its point of view).
...
...
@@ -316,44 +320,44 @@ void zmq::pipe_t::terminate (bool delay_)
delay
=
delay_
;
// If terminate was already called, we can ignore the duplicit invocation.
if
(
state
==
term
inated
||
state
==
double_terminated
)
if
(
state
==
term
_req_sent1
||
state
==
term_req_sent2
)
return
;
// If the pipe is in the final phase of async termination, it's going to
// closed anyway. No need to do anything special here.
else
if
(
state
==
term
inating
)
else
if
(
state
==
term
_ack_sent
)
return
;
// The simple sync termination case. Ask the peer to terminate and wait
// for the ack.
else
else
if
(
state
==
active
)
{
send_pipe_term
(
peer
);
state
=
term
inated
;
state
=
term
_req_sent1
;
}
// There are still pending messages available, but the user calls
// 'terminate'. We can act as if all the pending messages were read.
else
if
(
state
==
pending
&&
!
delay
)
{
else
if
(
state
==
waiting_for_delimiter
&&
delay
==
0
)
{
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
state
=
term
inating
;
state
=
term
_ack_sent
;
}
// If there are pending messages still availabe, do nothing.
else
if
(
state
==
pending
)
{
else
if
(
state
==
waiting_for_delimiter
)
{
}
// We've already got delimiter, but not term command yet. We can ignore
// the delimiter and ack synchronously terminate as if we were in
// active state.
else
if
(
state
==
delimited
)
{
else
if
(
state
==
delimite
r_receive
d
)
{
send_pipe_term
(
peer
);
state
=
term
inated
;
state
=
term
_req_sent1
;
}
// There are no other states.
...
...
@@ -413,14 +417,14 @@ int zmq::pipe_t::compute_lwm (int hwm_)
void
zmq
::
pipe_t
::
delimit
()
{
if
(
state
==
active
)
{
state
=
delimited
;
state
=
delimite
r_receive
d
;
return
;
}
if
(
state
==
pending
)
{
if
(
state
==
waiting_for_delimiter
)
{
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
state
=
term
inating
;
state
=
term
_ack_sent
;
return
;
}
...
...
src/pipe.hpp
View file @
9d63ebf6
...
...
@@ -162,22 +162,24 @@ namespace zmq
// Sink to send events to.
i_pipe_events
*
sink
;
// State of the pipe endpoint. Active is common state before any
// termination begins. Delimited means that delimiter was read from
// pipe before term command was received. Pending means that term
// command was already received from the peer but there are still
// pending messages to read. Terminating means that all pending
// messages were already read and all we are waiting for is ack from
// the peer. Terminated means that 'terminate' was explicitly called
// by the user. Double_terminated means that user called 'terminate'
// and then we've got term command from the peer as well.
// States of the pipe endpoint:
// active: common state before any termination begins,
// delimiter_received: delimiter was read from pipe before
// term command was received,
// waiting_fo_delimiter: term command was already received
// from the peer but there are still pending messages to read,
// term_ack_sent: all pending messages were already read and
// all we are waiting for is ack from the peer,
// term_req_sent1: 'terminate' was explicitly called by the user,
// term_req_sent2: user called 'terminate' and then we've got
// term command from the peer as well.
enum
{
active
,
delimited
,
pending
,
term
inating
,
term
inated
,
double_terminated
delimite
r_receive
d
,
waiting_for_delimiter
,
term
_ack_sent
,
term
_req_sent1
,
term_req_sent2
}
state
;
// If true, we receive all the pending inbound messages before
...
...
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