Problem: produce_* functions always return 0

Solution: change return type to void, and remove redundant result checks
This commit is contained in:
Simon Giesecke 2018-05-28 16:50:20 +02:00
parent 7f880c256f
commit d75ec5e055
4 changed files with 20 additions and 33 deletions

View File

@ -56,14 +56,12 @@ int zmq::plain_client_t::next_handshake_command (msg_t *msg_)
switch (_state) {
case sending_hello:
rc = produce_hello (msg_);
if (rc == 0)
_state = waiting_for_welcome;
produce_hello (msg_);
_state = waiting_for_welcome;
break;
case sending_initiate:
rc = produce_initiate (msg_);
if (rc == 0)
_state = waiting_for_ready;
produce_initiate (msg_);
_state = waiting_for_ready;
break;
default:
errno = EAGAIN;
@ -115,7 +113,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const
return mechanism_t::handshaking;
}
int zmq::plain_client_t::produce_hello (msg_t *msg_) const
void zmq::plain_client_t::produce_hello (msg_t *msg_) const
{
const std::string username = options.plain_username;
zmq_assert (username.length () <= UCHAR_MAX);
@ -140,8 +138,6 @@ int zmq::plain_client_t::produce_hello (msg_t *msg_) const
*ptr++ = static_cast<unsigned char> (password.length ());
memcpy (ptr, password.c_str (), password.length ());
return 0;
}
int zmq::plain_client_t::process_welcome (const unsigned char *cmd_data_,
@ -166,12 +162,10 @@ int zmq::plain_client_t::process_welcome (const unsigned char *cmd_data_,
return 0;
}
int zmq::plain_client_t::produce_initiate (msg_t *msg_) const
void zmq::plain_client_t::produce_initiate (msg_t *msg_) const
{
make_command_with_basic_properties (msg_, initiate_prefix,
initiate_prefix_len);
return 0;
}
int zmq::plain_client_t::process_ready (const unsigned char *cmd_data_,

View File

@ -61,8 +61,8 @@ class plain_client_t : public mechanism_base_t
state_t _state;
int produce_hello (msg_t *msg_) const;
int produce_initiate (msg_t *msg_) const;
void produce_hello (msg_t *msg_) const;
void produce_initiate (msg_t *msg_) const;
int process_welcome (const unsigned char *cmd_data_, size_t data_size_);
int process_ready (const unsigned char *cmd_data_, size_t data_size_);

View File

@ -64,19 +64,16 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_)
switch (state) {
case sending_welcome:
rc = produce_welcome (msg_);
if (rc == 0)
state = waiting_for_initiate;
produce_welcome (msg_);
state = waiting_for_initiate;
break;
case sending_ready:
rc = produce_ready (msg_);
if (rc == 0)
state = ready;
produce_ready (msg_);
state = ready;
break;
case sending_error:
rc = produce_error (msg_);
if (rc == 0)
state = error_sent;
produce_error (msg_);
state = error_sent;
break;
default:
errno = EAGAIN;
@ -204,12 +201,11 @@ int zmq::plain_server_t::process_hello (msg_t *msg_)
return receive_and_process_zap_reply () == -1 ? -1 : 0;
}
int zmq::plain_server_t::produce_welcome (msg_t *msg_) const
void zmq::plain_server_t::produce_welcome (msg_t *msg_) const
{
const int rc = msg_->init_size (welcome_prefix_len);
errno_assert (rc == 0);
memcpy (msg_->data (), welcome_prefix, welcome_prefix_len);
return 0;
}
int zmq::plain_server_t::process_initiate (msg_t *msg_)
@ -231,14 +227,12 @@ int zmq::plain_server_t::process_initiate (msg_t *msg_)
return rc;
}
int zmq::plain_server_t::produce_ready (msg_t *msg_) const
void zmq::plain_server_t::produce_ready (msg_t *msg_) const
{
make_command_with_basic_properties (msg_, ready_prefix, ready_prefix_len);
return 0;
}
int zmq::plain_server_t::produce_error (msg_t *msg_) const
void zmq::plain_server_t::produce_error (msg_t *msg_) const
{
const char expected_status_code_len = 3;
zmq_assert (status_code.length ()
@ -252,7 +246,6 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const
msg_data[error_prefix_len] = expected_status_code_len;
memcpy (msg_data + error_prefix_len + status_code_len_size,
status_code.c_str (), status_code.length ());
return 0;
}
void zmq::plain_server_t::send_zap_request (const std::string &username_,

View File

@ -51,9 +51,9 @@ class plain_server_t : public zap_client_common_handshake_t
virtual int process_handshake_command (msg_t *msg_);
private:
int produce_welcome (msg_t *msg_) const;
int produce_ready (msg_t *msg_) const;
int produce_error (msg_t *msg_) const;
void produce_welcome (msg_t *msg_) const;
void produce_ready (msg_t *msg_) const;
void produce_error (msg_t *msg_) const;
int process_hello (msg_t *msg_);
int process_initiate (msg_t *msg_);