mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-09 01:01:11 +08:00
All clients exit with an error exit code on CONNACK failure.
Closes #1778. Thanks to jflambert.
This commit is contained in:
parent
32ed4809ed
commit
9929ce0a26
@ -1,3 +1,7 @@
|
|||||||
|
Clients:
|
||||||
|
- All clients exit with an error exit code on CONNACK failure. Closes #1778.
|
||||||
|
|
||||||
|
|
||||||
1.6.11 - 2020-08-11
|
1.6.11 - 2020-08-11
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ static bool disconnect_sent = false;
|
|||||||
static int publish_count = 0;
|
static int publish_count = 0;
|
||||||
static bool ready_for_repeat = false;
|
static bool ready_for_repeat = false;
|
||||||
static volatile int status = STATUS_CONNECTING;
|
static volatile int status = STATUS_CONNECTING;
|
||||||
|
static int connack_result = 0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
static uint64_t next_publish_tv;
|
static uint64_t next_publish_tv;
|
||||||
@ -129,6 +130,8 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
|
|||||||
UNUSED(flags);
|
UNUSED(flags);
|
||||||
UNUSED(properties);
|
UNUSED(properties);
|
||||||
|
|
||||||
|
connack_result = result;
|
||||||
|
|
||||||
if(!result){
|
if(!result){
|
||||||
switch(cfg.pub_mode){
|
switch(cfg.pub_mode){
|
||||||
case MSGMODE_CMD:
|
case MSGMODE_CMD:
|
||||||
@ -555,7 +558,11 @@ int main(int argc, char *argv[])
|
|||||||
if(rc){
|
if(rc){
|
||||||
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
||||||
}
|
}
|
||||||
return rc;
|
if(connack_result){
|
||||||
|
return connack_result;
|
||||||
|
}else{
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
|
@ -52,6 +52,7 @@ extern struct mosq_config cfg;
|
|||||||
bool process_messages = true;
|
bool process_messages = true;
|
||||||
int msg_count = 0;
|
int msg_count = 0;
|
||||||
struct mosquitto *mosq = NULL;
|
struct mosquitto *mosq = NULL;
|
||||||
|
static int connack_result = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
void my_signal_handler(int signum)
|
void my_signal_handler(int signum)
|
||||||
@ -117,6 +118,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
|
|||||||
|
|
||||||
void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties)
|
void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flags, const mosquitto_property *properties)
|
||||||
{
|
{
|
||||||
|
connack_result = result;
|
||||||
if(!result){
|
if(!result){
|
||||||
client_state = rr_s_connected;
|
client_state = rr_s_connected;
|
||||||
mosquitto_subscribe_v5(mosq, NULL, cfg.response_topic, cfg.qos, 0, cfg.subscribe_props);
|
mosquitto_subscribe_v5(mosq, NULL, cfg.response_topic, cfg.qos, 0, cfg.subscribe_props);
|
||||||
@ -363,7 +365,11 @@ int main(int argc, char *argv[])
|
|||||||
if(rc){
|
if(rc){
|
||||||
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
||||||
}
|
}
|
||||||
return rc;
|
if(connack_result){
|
||||||
|
return connack_result;
|
||||||
|
}else{
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
mosquitto_lib_cleanup();
|
mosquitto_lib_cleanup();
|
||||||
|
@ -40,6 +40,7 @@ bool process_messages = true;
|
|||||||
int msg_count = 0;
|
int msg_count = 0;
|
||||||
struct mosquitto *mosq = NULL;
|
struct mosquitto *mosq = NULL;
|
||||||
int last_mid = 0;
|
int last_mid = 0;
|
||||||
|
static int connack_result = 0;
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
void my_signal_handler(int signum)
|
void my_signal_handler(int signum)
|
||||||
@ -117,6 +118,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag
|
|||||||
UNUSED(flags);
|
UNUSED(flags);
|
||||||
UNUSED(properties);
|
UNUSED(properties);
|
||||||
|
|
||||||
|
connack_result = result;
|
||||||
if(!result){
|
if(!result){
|
||||||
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);
|
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);
|
||||||
|
|
||||||
@ -371,7 +373,11 @@ int main(int argc, char *argv[])
|
|||||||
if(rc){
|
if(rc){
|
||||||
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
err_printf(&cfg, "Error: %s\n", mosquitto_strerror(rc));
|
||||||
}
|
}
|
||||||
return rc;
|
if(connack_result){
|
||||||
|
return connack_result;
|
||||||
|
}else{
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
mosquitto_destroy(mosq);
|
mosquitto_destroy(mosq);
|
||||||
|
@ -109,6 +109,64 @@
|
|||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Exit Status</title>
|
||||||
|
<para>
|
||||||
|
mosquitto_sub returns zero on success, or non-zero on error. If
|
||||||
|
the connection is refused by the broker at the MQTT level, then
|
||||||
|
the exit code is the CONNACK reason code. If another error
|
||||||
|
occurs, the exit code is a libmosquitto return value.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>MQTT v3.1.1 CONNACK codes:</para>
|
||||||
|
<itemizedlist mark="circle">
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>1</option> Connection refused: Bad protocol version</para></listitem>
|
||||||
|
<listitem><para><option>2</option> Connection refused: Identifier rejected</para></listitem>
|
||||||
|
<listitem><para><option>3</option> Connection refused: Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>4</option> Connection refused: Bad username/password</para></listitem>
|
||||||
|
<listitem><para><option>5</option> Connection refused: Not authorized</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
<para>MQTT v5 CONNACK codes:</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>128</option> Unspecified error</para></listitem>
|
||||||
|
<listitem><para><option>129</option> Malformed packet</para></listitem>
|
||||||
|
<listitem><para><option>130</option> Protocol error</para></listitem>
|
||||||
|
<listitem><para><option>131</option> Implementation specific error</para></listitem>
|
||||||
|
<listitem><para><option>132</option> Unsupported protocol version</para></listitem>
|
||||||
|
<listitem><para><option>133</option> Client ID not valid</para></listitem>
|
||||||
|
<listitem><para><option>134</option> Bad username or password</para></listitem>
|
||||||
|
<listitem><para><option>135</option> Not authorized</para></listitem>
|
||||||
|
<listitem><para><option>136</option> Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>137</option> Server busy</para></listitem>
|
||||||
|
<listitem><para><option>138</option> Banned</para></listitem>
|
||||||
|
<listitem><para><option>139</option> Server shutting down</para></listitem>
|
||||||
|
<listitem><para><option>140</option> Bad authentication method</para></listitem>
|
||||||
|
<listitem><para><option>141</option> Keep alive timeout</para></listitem>
|
||||||
|
<listitem><para><option>142</option> Session taken over</para></listitem>
|
||||||
|
<listitem><para><option>143</option> Topic filter invalid</para></listitem>
|
||||||
|
<listitem><para><option>144</option> Topic name invalid</para></listitem>
|
||||||
|
<listitem><para><option>147</option> Receive maximum exceeded</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Topic alias invalid</para></listitem>
|
||||||
|
<listitem><para><option>149</option> Packet too large</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Message rate too high</para></listitem>
|
||||||
|
<listitem><para><option>151</option> Quota exceeded</para></listitem>
|
||||||
|
<listitem><para><option>152</option> Administrative action</para></listitem>
|
||||||
|
<listitem><para><option>153</option> Payload format invalid</para></listitem>
|
||||||
|
<listitem><para><option>154</option> Retain not supported</para></listitem>
|
||||||
|
<listitem><para><option>155</option> QoS not supported</para></listitem>
|
||||||
|
<listitem><para><option>156</option> Use another server</para></listitem>
|
||||||
|
<listitem><para><option>157</option> Server moved</para></listitem>
|
||||||
|
<listitem><para><option>158</option> Shared subscriptions not supported</para></listitem>
|
||||||
|
<listitem><para><option>159</option> Connection rate exceeded</para></listitem>
|
||||||
|
<listitem><para><option>160</option> Maximum connect time</para></listitem>
|
||||||
|
<listitem><para><option>161</option> Subscription IDs not supported</para></listitem>
|
||||||
|
<listitem><para><option>162</option> Wildcard subscriptions not supported</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Examples</title>
|
<title>Examples</title>
|
||||||
<para>Add a user to a new password file:</para>
|
<para>Add a user to a new password file:</para>
|
||||||
|
@ -654,6 +654,64 @@
|
|||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Exit Status</title>
|
||||||
|
<para>
|
||||||
|
mosquitto_sub returns zero on success, or non-zero on error. If
|
||||||
|
the connection is refused by the broker at the MQTT level, then
|
||||||
|
the exit code is the CONNACK reason code. If another error
|
||||||
|
occurs, the exit code is a libmosquitto return value.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>MQTT v3.1.1 CONNACK codes:</para>
|
||||||
|
<itemizedlist mark="circle">
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>1</option> Connection refused: Bad protocol version</para></listitem>
|
||||||
|
<listitem><para><option>2</option> Connection refused: Identifier rejected</para></listitem>
|
||||||
|
<listitem><para><option>3</option> Connection refused: Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>4</option> Connection refused: Bad username/password</para></listitem>
|
||||||
|
<listitem><para><option>5</option> Connection refused: Not authorized</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
<para>MQTT v5 CONNACK codes:</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>128</option> Unspecified error</para></listitem>
|
||||||
|
<listitem><para><option>129</option> Malformed packet</para></listitem>
|
||||||
|
<listitem><para><option>130</option> Protocol error</para></listitem>
|
||||||
|
<listitem><para><option>131</option> Implementation specific error</para></listitem>
|
||||||
|
<listitem><para><option>132</option> Unsupported protocol version</para></listitem>
|
||||||
|
<listitem><para><option>133</option> Client ID not valid</para></listitem>
|
||||||
|
<listitem><para><option>134</option> Bad username or password</para></listitem>
|
||||||
|
<listitem><para><option>135</option> Not authorized</para></listitem>
|
||||||
|
<listitem><para><option>136</option> Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>137</option> Server busy</para></listitem>
|
||||||
|
<listitem><para><option>138</option> Banned</para></listitem>
|
||||||
|
<listitem><para><option>139</option> Server shutting down</para></listitem>
|
||||||
|
<listitem><para><option>140</option> Bad authentication method</para></listitem>
|
||||||
|
<listitem><para><option>141</option> Keep alive timeout</para></listitem>
|
||||||
|
<listitem><para><option>142</option> Session taken over</para></listitem>
|
||||||
|
<listitem><para><option>143</option> Topic filter invalid</para></listitem>
|
||||||
|
<listitem><para><option>144</option> Topic name invalid</para></listitem>
|
||||||
|
<listitem><para><option>147</option> Receive maximum exceeded</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Topic alias invalid</para></listitem>
|
||||||
|
<listitem><para><option>149</option> Packet too large</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Message rate too high</para></listitem>
|
||||||
|
<listitem><para><option>151</option> Quota exceeded</para></listitem>
|
||||||
|
<listitem><para><option>152</option> Administrative action</para></listitem>
|
||||||
|
<listitem><para><option>153</option> Payload format invalid</para></listitem>
|
||||||
|
<listitem><para><option>154</option> Retain not supported</para></listitem>
|
||||||
|
<listitem><para><option>155</option> QoS not supported</para></listitem>
|
||||||
|
<listitem><para><option>156</option> Use another server</para></listitem>
|
||||||
|
<listitem><para><option>157</option> Server moved</para></listitem>
|
||||||
|
<listitem><para><option>158</option> Shared subscriptions not supported</para></listitem>
|
||||||
|
<listitem><para><option>159</option> Connection rate exceeded</para></listitem>
|
||||||
|
<listitem><para><option>160</option> Maximum connect time</para></listitem>
|
||||||
|
<listitem><para><option>161</option> Subscription IDs not supported</para></listitem>
|
||||||
|
<listitem><para><option>162</option> Wildcard subscriptions not supported</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Examples</title>
|
<title>Examples</title>
|
||||||
<para>Publish temperature information to localhost with QoS 1:</para>
|
<para>Publish temperature information to localhost with QoS 1:</para>
|
||||||
|
@ -893,6 +893,64 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained</programlisting>
|
|||||||
</refsect2>
|
</refsect2>
|
||||||
</refsect1>
|
</refsect1>
|
||||||
|
|
||||||
|
<refsect1>
|
||||||
|
<title>Exit Status</title>
|
||||||
|
<para>
|
||||||
|
mosquitto_sub returns zero on success, or non-zero on error. If
|
||||||
|
the connection is refused by the broker at the MQTT level, then
|
||||||
|
the exit code is the CONNACK reason code. If another error
|
||||||
|
occurs, the exit code is a libmosquitto return value.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>MQTT v3.1.1 CONNACK codes:</para>
|
||||||
|
<itemizedlist mark="circle">
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>1</option> Connection refused: Bad protocol version</para></listitem>
|
||||||
|
<listitem><para><option>2</option> Connection refused: Identifier rejected</para></listitem>
|
||||||
|
<listitem><para><option>3</option> Connection refused: Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>4</option> Connection refused: Bad username/password</para></listitem>
|
||||||
|
<listitem><para><option>5</option> Connection refused: Not authorized</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
|
||||||
|
<para>MQTT v5 CONNACK codes:</para>
|
||||||
|
<itemizedlist>
|
||||||
|
<listitem><para><option>0</option> Success</para></listitem>
|
||||||
|
<listitem><para><option>128</option> Unspecified error</para></listitem>
|
||||||
|
<listitem><para><option>129</option> Malformed packet</para></listitem>
|
||||||
|
<listitem><para><option>130</option> Protocol error</para></listitem>
|
||||||
|
<listitem><para><option>131</option> Implementation specific error</para></listitem>
|
||||||
|
<listitem><para><option>132</option> Unsupported protocol version</para></listitem>
|
||||||
|
<listitem><para><option>133</option> Client ID not valid</para></listitem>
|
||||||
|
<listitem><para><option>134</option> Bad username or password</para></listitem>
|
||||||
|
<listitem><para><option>135</option> Not authorized</para></listitem>
|
||||||
|
<listitem><para><option>136</option> Server unavailable</para></listitem>
|
||||||
|
<listitem><para><option>137</option> Server busy</para></listitem>
|
||||||
|
<listitem><para><option>138</option> Banned</para></listitem>
|
||||||
|
<listitem><para><option>139</option> Server shutting down</para></listitem>
|
||||||
|
<listitem><para><option>140</option> Bad authentication method</para></listitem>
|
||||||
|
<listitem><para><option>141</option> Keep alive timeout</para></listitem>
|
||||||
|
<listitem><para><option>142</option> Session taken over</para></listitem>
|
||||||
|
<listitem><para><option>143</option> Topic filter invalid</para></listitem>
|
||||||
|
<listitem><para><option>144</option> Topic name invalid</para></listitem>
|
||||||
|
<listitem><para><option>147</option> Receive maximum exceeded</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Topic alias invalid</para></listitem>
|
||||||
|
<listitem><para><option>149</option> Packet too large</para></listitem>
|
||||||
|
<listitem><para><option>148</option> Message rate too high</para></listitem>
|
||||||
|
<listitem><para><option>151</option> Quota exceeded</para></listitem>
|
||||||
|
<listitem><para><option>152</option> Administrative action</para></listitem>
|
||||||
|
<listitem><para><option>153</option> Payload format invalid</para></listitem>
|
||||||
|
<listitem><para><option>154</option> Retain not supported</para></listitem>
|
||||||
|
<listitem><para><option>155</option> QoS not supported</para></listitem>
|
||||||
|
<listitem><para><option>156</option> Use another server</para></listitem>
|
||||||
|
<listitem><para><option>157</option> Server moved</para></listitem>
|
||||||
|
<listitem><para><option>158</option> Shared subscriptions not supported</para></listitem>
|
||||||
|
<listitem><para><option>159</option> Connection rate exceeded</para></listitem>
|
||||||
|
<listitem><para><option>160</option> Maximum connect time</para></listitem>
|
||||||
|
<listitem><para><option>161</option> Subscription IDs not supported</para></listitem>
|
||||||
|
<listitem><para><option>162</option> Wildcard subscriptions not supported</para></listitem>
|
||||||
|
</itemizedlist>
|
||||||
|
</refsect1>
|
||||||
|
|
||||||
<refsect1>
|
<refsect1>
|
||||||
<title>Examples</title>
|
<title>Examples</title>
|
||||||
<para>Note that these really are examples - the subscriptions will work
|
<para>Note that these really are examples - the subscriptions will work
|
||||||
|
Loading…
x
Reference in New Issue
Block a user