Commit 314a3acf authored by sigiesec's avatar sigiesec

Problem: status method duplicated between curve_server_t and plain_server_t

Solution: extract into new intermediate base class zap_client_common_handshake_t
parent ebba815a
......@@ -42,8 +42,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *session_,
const std::string &peer_address_,
const options_t &options_) :
mechanism_t (options_),
zap_client_t (session_, peer_address_, options_),
state (waiting_for_hello),
zap_client_common_handshake_t (session_, peer_address_, options_),
current_error_detail (no_detail),
cn_nonce (1),
cn_peer_nonce (1)
......@@ -260,17 +259,6 @@ int zmq::curve_server_t::zap_msg_available ()
return rc;
}
zmq::mechanism_t::status_t zmq::curve_server_t::status () const
{
if (state == ready)
return mechanism_t::ready;
else
if (state == error_sent)
return mechanism_t::error;
else
return mechanism_t::handshaking;
}
zmq::mechanism_t::error_detail_t zmq::curve_server_t::error_detail() const
{
return current_error_detail;
......
......@@ -59,7 +59,7 @@ namespace zmq
class msg_t;
class session_base_t;
class curve_server_t : public zap_client_t
class curve_server_t : public zap_client_common_handshake_t
{
public:
......@@ -74,14 +74,10 @@ namespace zmq
virtual int encode (msg_t *msg_);
virtual int decode (msg_t *msg_);
virtual int zap_msg_available ();
virtual status_t status () const;
virtual error_detail_t error_detail () const;
private:
// Current FSM state
state_t state;
// Details about the current error state
error_detail_t current_error_detail;
......
......@@ -41,8 +41,7 @@ zmq::plain_server_t::plain_server_t (session_base_t *session_,
const std::string &peer_address_,
const options_t &options_) :
mechanism_t (options_),
zap_client_t (session_, peer_address_, options_),
state (waiting_for_hello)
zap_client_common_handshake_t (session_, peer_address_, options_)
{
}
......@@ -104,17 +103,6 @@ int zmq::plain_server_t::process_handshake_command (msg_t *msg_)
return rc;
}
zmq::mechanism_t::status_t zmq::plain_server_t::status () const
{
if (state == ready)
return mechanism_t::ready;
else
if (state == error_sent)
return mechanism_t::error;
else
return mechanism_t::handshaking;
}
int zmq::plain_server_t::zap_msg_available ()
{
if (state != waiting_for_zap_reply) {
......
......@@ -40,7 +40,7 @@ namespace zmq
class msg_t;
class session_base_t;
class plain_server_t : public zap_client_t
class plain_server_t : public zap_client_common_handshake_t
{
public:
......@@ -53,7 +53,6 @@ namespace zmq
virtual int next_handshake_command (msg_t *msg_);
virtual int process_handshake_command (msg_t *msg_);
virtual int zap_msg_available ();
virtual status_t status () const;
private:
......
......@@ -220,4 +220,23 @@ int zap_client_t::receive_and_process_zap_reply ()
return 0;
}
zap_client_common_handshake_t::zap_client_common_handshake_t (
session_base_t *const session_,
const std::string &peer_address_,
const options_t &options_) :
zap_client_t (session_, peer_address_, options_),
state (waiting_for_hello)
{
}
zmq::mechanism_t::status_t zap_client_common_handshake_t::status () const
{
if (state == ready)
return mechanism_t::ready;
else if (state == error_sent)
return mechanism_t::error;
else
return mechanism_t::handshaking;
}
}
......@@ -63,6 +63,17 @@ class zap_client_t : public virtual mechanism_t
// Status code as received from ZAP handler
std::string status_code;
};
class zap_client_common_handshake_t : public zap_client_t
{
protected:
zap_client_common_handshake_t (session_base_t *const session_,
const std::string &peer_address_,
const options_t &options_);
// methods from mechanism_t
status_t status () const;
enum state_t
{
......@@ -75,6 +86,9 @@ class zap_client_t : public virtual mechanism_t
error_sent,
ready
};
// Current FSM state
state_t state;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment