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