Commit 4d640fe0 authored by Pieter Hintjens's avatar Pieter Hintjens

Merge pull request #1012 from hurtonm/master

Update mechanism API so we can check for ERROR status
parents 8672f302 43d82524
......@@ -206,9 +206,9 @@ int zmq::curve_client_t::decode (msg_t *msg_)
return rc;
}
bool zmq::curve_client_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::curve_client_t::status () const
{
return state == connected;
return state == connected? mechanism_t::ready: mechanism_t::handshaking;
}
int zmq::curve_client_t::produce_hello (msg_t *msg_)
......
......@@ -59,7 +59,7 @@ namespace zmq
virtual int process_handshake_command (msg_t *msg_);
virtual int encode (msg_t *msg_);
virtual int decode (msg_t *msg_);
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -237,9 +237,9 @@ int zmq::curve_server_t::zap_msg_available ()
return rc;
}
bool zmq::curve_server_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::curve_server_t::status () const
{
return state == connected;
return state == connected? mechanism_t::ready: mechanism_t::handshaking;
}
int zmq::curve_server_t::process_hello (msg_t *msg_)
......
......@@ -64,7 +64,7 @@ namespace zmq
virtual int encode (msg_t *msg_);
virtual int decode (msg_t *msg_);
virtual int zap_msg_available ();
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -153,9 +153,9 @@ int zmq::gssapi_client_t::decode (msg_t *msg_)
return 0;
}
bool zmq::gssapi_client_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::gssapi_client_t::status () const
{
return state == connected;
return state == connected? mechanism_t::ready: mechanism_t::handshaking;
}
int zmq::gssapi_client_t::initialize_context ()
......
......@@ -42,7 +42,7 @@ namespace zmq
virtual int process_handshake_command (msg_t *msg_);
virtual int encode (msg_t *msg_);
virtual int decode (msg_t *msg_);
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -315,9 +315,9 @@ int zmq::gssapi_server_t::zap_msg_available ()
return rc;
}
bool zmq::gssapi_server_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::gssapi_server_t::status () const
{
return state == connected;
return state == connected? mechanism_t::ready: mechanism_t::handshaking;
}
int zmq::gssapi_server_t::produce_next_token (msg_t *msg_)
......
......@@ -46,7 +46,7 @@ namespace zmq
virtual int encode (msg_t *msg_);
virtual int decode (msg_t *msg_);
virtual int zap_msg_available ();
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -37,6 +37,12 @@ namespace zmq
{
public:
enum status_t {
handshaking,
ready,
error
};
mechanism_t (const options_t &options_);
virtual ~mechanism_t ();
......@@ -54,8 +60,8 @@ namespace zmq
// Notifies mechanism about availability of ZAP message.
virtual int zap_msg_available () { return 0; }
// True iff the handshake stage is complete?
virtual bool is_handshake_complete () const = 0;
// Returns the status of this mechanism.
virtual status_t status () const = 0;
void set_peer_identity (const void *id_ptr, size_t id_size);
......
......@@ -152,9 +152,12 @@ int zmq::null_mechanism_t::zap_msg_available ()
return rc;
}
bool zmq::null_mechanism_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
{
return ready_command_received && ready_command_sent;
if (ready_command_received && ready_command_sent)
return mechanism_t::ready;
else
return mechanism_t::handshaking;
}
void zmq::null_mechanism_t::send_zap_request ()
......
......@@ -42,7 +42,7 @@ namespace zmq
virtual int next_handshake_command (msg_t *msg_);
virtual int process_handshake_command (msg_t *msg_);
virtual int zap_msg_available ();
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -118,9 +118,9 @@ int zmq::plain_mechanism_t::process_handshake_command (msg_t *msg_)
return rc;
}
bool zmq::plain_mechanism_t::is_handshake_complete () const
zmq::mechanism_t::status_t zmq::plain_mechanism_t::status () const
{
return state == ready;
return state == ready? mechanism_t::ready: mechanism_t::handshaking;
}
int zmq::plain_mechanism_t::zap_msg_available ()
......
......@@ -42,7 +42,7 @@ namespace zmq
virtual int next_handshake_command (msg_t *msg_);
virtual int process_handshake_command (msg_t *msg_);
virtual int zap_msg_available ();
virtual bool is_handshake_complete () const;
virtual status_t status () const;
private:
......
......@@ -670,17 +670,21 @@ int zmq::stream_engine_t::next_handshake_command (msg_t *msg_)
{
zmq_assert (mechanism != NULL);
const int rc = mechanism->next_handshake_command (msg_);
if (rc == 0) {
msg_->set_flags (msg_t::command);
if (mechanism->is_handshake_complete ())
mechanism_ready ();
if (mechanism->status () == mechanism_t::ready) {
mechanism_ready ();
return pull_and_encode (msg_);
}
else
if (mechanism->status () == mechanism_t::error) {
errno = EPROTO;
return -1;
}
else {
const int rc = mechanism->next_handshake_command (msg_);
if (rc == 0)
msg_->set_flags (msg_t::command);
return rc;
}
// TODO:
// if (errno == EPROTO || errno == EACCES)
// return ERROR command to client
return rc;
}
int zmq::stream_engine_t::process_handshake_command (msg_t *msg_)
......@@ -688,14 +692,16 @@ int zmq::stream_engine_t::process_handshake_command (msg_t *msg_)
zmq_assert (mechanism != NULL);
const int rc = mechanism->process_handshake_command (msg_);
if (rc == 0) {
if (mechanism->is_handshake_complete ())
if (mechanism->status () == mechanism_t::ready)
mechanism_ready ();
else
if (mechanism->status () == mechanism_t::error) {
errno = EPROTO;
return -1;
}
if (output_stopped)
restart_output ();
}
// TODO:
// if (errno == EPROTO || errno == EACCES)
// return ERROR command to client
return rc;
}
......
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