Merge pull request #1012 from hurtonm/master

Update mechanism API so we can check for ERROR status
This commit is contained in:
Pieter Hintjens 2014-05-06 17:53:39 +02:00
commit 4d640fe010
14 changed files with 49 additions and 34 deletions

View File

@ -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_)

View File

@ -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:

View File

@ -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_)

View File

@ -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:

View File

@ -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 ()

View File

@ -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:

View File

@ -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_)

View File

@ -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:

View File

@ -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);

View File

@ -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 ()

View File

@ -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:

View File

@ -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 ()

View File

@ -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:

View File

@ -670,32 +670,38 @@ 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 ())
if (mechanism->status () == mechanism_t::ready) {
mechanism_ready ();
return pull_and_encode (msg_);
}
// TODO:
// if (errno == EPROTO || errno == EACCES)
// return ERROR command to client
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;
}
}
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;
}