mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-03 12:58:05 +01:00
Problem: deviating behavior regarding monitoring events between mechanisms
Solution: move relevant behavior to zap_client_t
This commit is contained in:
parent
406af1ef67
commit
f107b53768
@ -40,7 +40,8 @@ zap_client_t::zap_client_t (session_base_t *const session_,
|
|||||||
const options_t &options_) :
|
const options_t &options_) :
|
||||||
mechanism_t (options_),
|
mechanism_t (options_),
|
||||||
session (session_),
|
session (session_),
|
||||||
peer_address (peer_address_)
|
peer_address (peer_address_),
|
||||||
|
current_error_detail (no_detail)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +169,7 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
if ((msg[i].flags () & msg_t::more) == (i < 6 ? 0 : msg_t::more)) {
|
if ((msg[i].flags () & msg_t::more) == (i < 6 ? 0 : msg_t::more)) {
|
||||||
// CURVE I : ZAP handler sent incomplete reply message
|
// CURVE I : ZAP handler sent incomplete reply message
|
||||||
errno = EPROTO;
|
errno = EPROTO;
|
||||||
|
current_error_detail = mechanism_t::zap;
|
||||||
return close_and_return (msg, -1);
|
return close_and_return (msg, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,6 +178,7 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
if (msg[0].size () > 0) {
|
if (msg[0].size () > 0) {
|
||||||
// CURVE I: ZAP handler sent malformed reply message
|
// CURVE I: ZAP handler sent malformed reply message
|
||||||
errno = EPROTO;
|
errno = EPROTO;
|
||||||
|
current_error_detail = mechanism_t::zap;
|
||||||
return close_and_return (msg, -1);
|
return close_and_return (msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,6 +186,7 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
if (msg[1].size () != 3 || memcmp (msg[1].data (), "1.0", 3)) {
|
if (msg[1].size () != 3 || memcmp (msg[1].data (), "1.0", 3)) {
|
||||||
// CURVE I: ZAP handler sent bad version number
|
// CURVE I: ZAP handler sent bad version number
|
||||||
errno = EPROTO;
|
errno = EPROTO;
|
||||||
|
current_error_detail = mechanism_t::zap;
|
||||||
return close_and_return (msg, -1);
|
return close_and_return (msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +194,7 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
if (msg[2].size () != 1 || memcmp (msg[2].data (), "1", 1)) {
|
if (msg[2].size () != 1 || memcmp (msg[2].data (), "1", 1)) {
|
||||||
// CURVE I: ZAP handler sent bad request ID
|
// CURVE I: ZAP handler sent bad request ID
|
||||||
errno = EPROTO;
|
errno = EPROTO;
|
||||||
|
current_error_detail = mechanism_t::zap;
|
||||||
return close_and_return (msg, -1);
|
return close_and_return (msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,6 +205,7 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
|| status_code_data[2] != '0') {
|
|| status_code_data[2] != '0') {
|
||||||
// CURVE I: ZAP handler sent invalid status code
|
// CURVE I: ZAP handler sent invalid status code
|
||||||
errno = EPROTO;
|
errno = EPROTO;
|
||||||
|
current_error_detail = mechanism_t::zap;
|
||||||
return close_and_return (msg, -1);
|
return close_and_return (msg, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,6 +234,36 @@ int zap_client_t::receive_and_process_zap_reply ()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void zap_client_t::handle_zap_status_code ()
|
||||||
|
{
|
||||||
|
// we can assume here that status_code is a valid ZAP status code,
|
||||||
|
// i.e. 200, 300, 400 or 500
|
||||||
|
int err = 0;
|
||||||
|
switch (status_code[0]) {
|
||||||
|
case '2':
|
||||||
|
return;
|
||||||
|
case '3':
|
||||||
|
err = EAGAIN;
|
||||||
|
break;
|
||||||
|
case '4':
|
||||||
|
err = EACCES;
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
err = EFAULT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// TODO use event_handshake_failed_zap here? but this is not a ZAP
|
||||||
|
// protocol error
|
||||||
|
|
||||||
|
session->get_socket ()->event_handshake_failed_no_detail (
|
||||||
|
session->get_endpoint (), err);
|
||||||
|
}
|
||||||
|
|
||||||
|
mechanism_t::error_detail_t zap_client_t::error_detail () const
|
||||||
|
{
|
||||||
|
return current_error_detail;
|
||||||
|
}
|
||||||
|
|
||||||
zap_client_common_handshake_t::zap_client_common_handshake_t (
|
zap_client_common_handshake_t::zap_client_common_handshake_t (
|
||||||
session_base_t *const session_,
|
session_base_t *const session_,
|
||||||
const std::string &peer_address_,
|
const std::string &peer_address_,
|
||||||
@ -236,7 +272,6 @@ zap_client_common_handshake_t::zap_client_common_handshake_t (
|
|||||||
mechanism_t (options_),
|
mechanism_t (options_),
|
||||||
zap_client_t (session_, peer_address_, options_),
|
zap_client_t (session_, peer_address_, options_),
|
||||||
state (waiting_for_hello),
|
state (waiting_for_hello),
|
||||||
current_error_detail (no_detail),
|
|
||||||
zap_reply_ok_state (zap_reply_ok_state_)
|
zap_reply_ok_state (zap_reply_ok_state_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -265,53 +300,23 @@ int zap_client_common_handshake_t::zap_msg_available ()
|
|||||||
|
|
||||||
void zap_client_common_handshake_t::handle_zap_status_code ()
|
void zap_client_common_handshake_t::handle_zap_status_code ()
|
||||||
{
|
{
|
||||||
|
zap_client_t::handle_zap_status_code ();
|
||||||
|
|
||||||
// we can assume here that status_code is a valid ZAP status code,
|
// we can assume here that status_code is a valid ZAP status code,
|
||||||
// i.e. 200, 300, 400 or 500
|
// i.e. 200, 300, 400 or 500
|
||||||
if (status_code[0] == '2') {
|
if (status_code[0] == '2') {
|
||||||
state = zap_reply_ok_state;
|
state = zap_reply_ok_state;
|
||||||
} else {
|
} else {
|
||||||
state = sending_error;
|
state = sending_error;
|
||||||
|
|
||||||
int err = 0;
|
|
||||||
switch (status_code[0]) {
|
|
||||||
case '3':
|
|
||||||
err = EAGAIN;
|
|
||||||
break;
|
|
||||||
case '4':
|
|
||||||
err = EACCES;
|
|
||||||
break;
|
|
||||||
case '5':
|
|
||||||
err = EFAULT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// TODO use event_handshake_failed_zap here? but this is not a ZAP
|
|
||||||
// protocol error
|
|
||||||
|
|
||||||
session->get_socket ()->event_handshake_failed_no_detail (
|
|
||||||
session->get_endpoint (), err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mechanism_t::error_detail_t zap_client_common_handshake_t::error_detail () const
|
|
||||||
{
|
|
||||||
return current_error_detail;
|
|
||||||
}
|
|
||||||
|
|
||||||
int zap_client_common_handshake_t::receive_and_process_zap_reply ()
|
int zap_client_common_handshake_t::receive_and_process_zap_reply ()
|
||||||
{
|
{
|
||||||
int rc = zap_client_t::receive_and_process_zap_reply ();
|
int rc = zap_client_t::receive_and_process_zap_reply ();
|
||||||
switch (rc) {
|
if (rc == 1)
|
||||||
case -1:
|
// TODO shouldn't the state already be this?
|
||||||
if (errno == EPROTO)
|
state = waiting_for_zap_reply;
|
||||||
current_error_detail = mechanism_t::zap;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
// TODO shouldn't the state already be this?
|
|
||||||
state = waiting_for_zap_reply;
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,10 @@ class zap_client_t : public virtual mechanism_t
|
|||||||
size_t credentials_count);
|
size_t credentials_count);
|
||||||
|
|
||||||
virtual int receive_and_process_zap_reply ();
|
virtual int receive_and_process_zap_reply ();
|
||||||
virtual void handle_zap_status_code () {}
|
virtual void handle_zap_status_code ();
|
||||||
|
|
||||||
|
// methods from mechanism_t
|
||||||
|
error_detail_t error_detail () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
session_base_t *const session;
|
session_base_t *const session;
|
||||||
@ -63,6 +66,10 @@ class zap_client_t : public virtual mechanism_t
|
|||||||
|
|
||||||
// Status code as received from ZAP handler
|
// Status code as received from ZAP handler
|
||||||
std::string status_code;
|
std::string status_code;
|
||||||
|
|
||||||
|
// Details about the current error state
|
||||||
|
// TODO remove this
|
||||||
|
error_detail_t current_error_detail;
|
||||||
};
|
};
|
||||||
|
|
||||||
class zap_client_common_handshake_t : public zap_client_t
|
class zap_client_common_handshake_t : public zap_client_t
|
||||||
@ -88,7 +95,6 @@ class zap_client_common_handshake_t : public zap_client_t
|
|||||||
// methods from mechanism_t
|
// methods from mechanism_t
|
||||||
status_t status () const;
|
status_t status () const;
|
||||||
int zap_msg_available ();
|
int zap_msg_available ();
|
||||||
error_detail_t error_detail () const;
|
|
||||||
|
|
||||||
// zap_client_t methods
|
// zap_client_t methods
|
||||||
int receive_and_process_zap_reply ();
|
int receive_and_process_zap_reply ();
|
||||||
@ -97,10 +103,6 @@ class zap_client_common_handshake_t : public zap_client_t
|
|||||||
// Current FSM state
|
// Current FSM state
|
||||||
state_t state;
|
state_t state;
|
||||||
|
|
||||||
// Details about the current error state
|
|
||||||
// TODO remove this
|
|
||||||
error_detail_t current_error_detail;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const state_t zap_reply_ok_state;
|
const state_t zap_reply_ok_state;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user