Commit d75ec5e0 authored by Simon Giesecke's avatar Simon Giesecke

Problem: produce_* functions always return 0

Solution: change return type to void, and remove redundant result checks
parent 7f880c25
...@@ -56,14 +56,12 @@ int zmq::plain_client_t::next_handshake_command (msg_t *msg_) ...@@ -56,14 +56,12 @@ int zmq::plain_client_t::next_handshake_command (msg_t *msg_)
switch (_state) { switch (_state) {
case sending_hello: case sending_hello:
rc = produce_hello (msg_); produce_hello (msg_);
if (rc == 0) _state = waiting_for_welcome;
_state = waiting_for_welcome;
break; break;
case sending_initiate: case sending_initiate:
rc = produce_initiate (msg_); produce_initiate (msg_);
if (rc == 0) _state = waiting_for_ready;
_state = waiting_for_ready;
break; break;
default: default:
errno = EAGAIN; errno = EAGAIN;
...@@ -115,7 +113,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const ...@@ -115,7 +113,7 @@ zmq::mechanism_t::status_t zmq::plain_client_t::status () const
return mechanism_t::handshaking; 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; const std::string username = options.plain_username;
zmq_assert (username.length () <= UCHAR_MAX); zmq_assert (username.length () <= UCHAR_MAX);
...@@ -140,8 +138,6 @@ int zmq::plain_client_t::produce_hello (msg_t *msg_) const ...@@ -140,8 +138,6 @@ int zmq::plain_client_t::produce_hello (msg_t *msg_) const
*ptr++ = static_cast<unsigned char> (password.length ()); *ptr++ = static_cast<unsigned char> (password.length ());
memcpy (ptr, password.c_str (), password.length ()); memcpy (ptr, password.c_str (), password.length ());
return 0;
} }
int zmq::plain_client_t::process_welcome (const unsigned char *cmd_data_, 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_, ...@@ -166,12 +162,10 @@ int zmq::plain_client_t::process_welcome (const unsigned char *cmd_data_,
return 0; 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, make_command_with_basic_properties (msg_, initiate_prefix,
initiate_prefix_len); initiate_prefix_len);
return 0;
} }
int zmq::plain_client_t::process_ready (const unsigned char *cmd_data_, int zmq::plain_client_t::process_ready (const unsigned char *cmd_data_,
......
...@@ -61,8 +61,8 @@ class plain_client_t : public mechanism_base_t ...@@ -61,8 +61,8 @@ class plain_client_t : public mechanism_base_t
state_t _state; state_t _state;
int produce_hello (msg_t *msg_) const; void produce_hello (msg_t *msg_) const;
int produce_initiate (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_welcome (const unsigned char *cmd_data_, size_t data_size_);
int process_ready (const unsigned char *cmd_data_, size_t data_size_); int process_ready (const unsigned char *cmd_data_, size_t data_size_);
......
...@@ -64,19 +64,16 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_) ...@@ -64,19 +64,16 @@ int zmq::plain_server_t::next_handshake_command (msg_t *msg_)
switch (state) { switch (state) {
case sending_welcome: case sending_welcome:
rc = produce_welcome (msg_); produce_welcome (msg_);
if (rc == 0) state = waiting_for_initiate;
state = waiting_for_initiate;
break; break;
case sending_ready: case sending_ready:
rc = produce_ready (msg_); produce_ready (msg_);
if (rc == 0) state = ready;
state = ready;
break; break;
case sending_error: case sending_error:
rc = produce_error (msg_); produce_error (msg_);
if (rc == 0) state = error_sent;
state = error_sent;
break; break;
default: default:
errno = EAGAIN; errno = EAGAIN;
...@@ -204,12 +201,11 @@ int zmq::plain_server_t::process_hello (msg_t *msg_) ...@@ -204,12 +201,11 @@ int zmq::plain_server_t::process_hello (msg_t *msg_)
return receive_and_process_zap_reply () == -1 ? -1 : 0; 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); const int rc = msg_->init_size (welcome_prefix_len);
errno_assert (rc == 0); errno_assert (rc == 0);
memcpy (msg_->data (), welcome_prefix, welcome_prefix_len); memcpy (msg_->data (), welcome_prefix, welcome_prefix_len);
return 0;
} }
int zmq::plain_server_t::process_initiate (msg_t *msg_) int zmq::plain_server_t::process_initiate (msg_t *msg_)
...@@ -231,14 +227,12 @@ 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; 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); 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; const char expected_status_code_len = 3;
zmq_assert (status_code.length () zmq_assert (status_code.length ()
...@@ -252,7 +246,6 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const ...@@ -252,7 +246,6 @@ int zmq::plain_server_t::produce_error (msg_t *msg_) const
msg_data[error_prefix_len] = expected_status_code_len; msg_data[error_prefix_len] = expected_status_code_len;
memcpy (msg_data + error_prefix_len + status_code_len_size, memcpy (msg_data + error_prefix_len + status_code_len_size,
status_code.c_str (), status_code.length ()); status_code.c_str (), status_code.length ());
return 0;
} }
void zmq::plain_server_t::send_zap_request (const std::string &username_, void zmq::plain_server_t::send_zap_request (const std::string &username_,
......
...@@ -51,9 +51,9 @@ class plain_server_t : public zap_client_common_handshake_t ...@@ -51,9 +51,9 @@ class plain_server_t : public zap_client_common_handshake_t
virtual int process_handshake_command (msg_t *msg_); virtual int process_handshake_command (msg_t *msg_);
private: private:
int produce_welcome (msg_t *msg_) const; void produce_welcome (msg_t *msg_) const;
int produce_ready (msg_t *msg_) const; void produce_ready (msg_t *msg_) const;
int produce_error (msg_t *msg_) const; void produce_error (msg_t *msg_) const;
int process_hello (msg_t *msg_); int process_hello (msg_t *msg_);
int process_initiate (msg_t *msg_); int process_initiate (msg_t *msg_);
......
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