mco_iot_conn_get_error
此函数接收在 onDisconnect()
和 onDestroy()
回调中最后一个错误的错误描述,以查明连接中断的原因。
void mco_iot_conn_get_error(
iot_connection_h iotc,
mco_iot_stop_reason_t *reason,
MCO_RET *last_error,
int *last_errno,
char *message,
int message_len
);
有关概述,请参阅主动复制结构页面。
参数
iotc
iot_connection_h
连接句柄。
reason
mco_iot_stop_reason_t
以下枚举值之一:
typedef enum mco_iot_stop_reason_t_ {
MCO_IOT_STOP_REASON_NONE = 0,
MCO_IOT_STOP_REASON_NETWORK_ERROR,
MCO_IOT_STOP_REASON_CALLBACK_FAILED,
MCO_IOT_STOP_REASON_IOT_STOPPED,
MCO_IOT_STOP_REASON_USER_REQUEST
} mco_iot_stop_reason_t;
last_error
MCO_RET
最后一个错误代码;MCO_E_*
值之一。
last_errno
int
最后一个网络错误代码:仅对网络错误有意义。
message
char
用于接收错误消息文本的缓冲区。
message_len
int
错误消息缓冲区大小。
返回
无返回值。
示例
// onDisconnect回调
int iot_on_disconnect(mco_iot_connection_h iotc, void *context)
{
char errmsg[128];
mco_iot_stop_reason_t stop_reason;
MCO_RET last_error;
int last_errno;
mco_iot_conn_get_error(iotc, &stop_reason, &last_error, &last_errno, errmsg, sizeof(errmsg));
printf("IoT device %llu disconnected. Reason %d, errcode %d. errno %d : <%s>",
mco_iot_conn_get_agent_id(iotc), stop_reason, last_error, last_errno, errmsg);
return IOT_CALLBACK_OK;
}
文件
- 头文件:
mcoiot.h
- 源文件:
mcoiotcomm.c
- 库:
libmcoiotcomm.a