diff options
Diffstat (limited to '')
-rw-r--r-- | src/aclk/mqtt_websockets/mqtt_wss_client.c (renamed from mqtt_websockets/src/mqtt_wss_client.c) | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/mqtt_websockets/src/mqtt_wss_client.c b/src/aclk/mqtt_websockets/mqtt_wss_client.c index 01e2ffce7..a2aef80ce 100644 --- a/mqtt_websockets/src/mqtt_wss_client.c +++ b/src/aclk/mqtt_websockets/mqtt_wss_client.c @@ -1,16 +1,9 @@ -// Copyright (C) 2020 Timotej Šiškovič // SPDX-License-Identifier: GPL-3.0-only -// -// This program is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free Software Foundation, version 3. -// -// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; -// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License along with this program. -// If not, see <https://www.gnu.org/licenses/>. +// Copyright (C) 2020 Timotej Šiškovič + +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include "mqtt_wss_client.h" #include "mqtt_ng.h" @@ -152,16 +145,16 @@ static void mws_connack_callback_ng(void *user_ctx, int code) static ssize_t mqtt_send_cb(void *user_ctx, const void* buf, size_t len) { - mqtt_wss_client mqtt_wss_client = user_ctx; + mqtt_wss_client client = user_ctx; #ifdef DEBUG_ULTRA_VERBOSE - mws_debug(mqtt_wss_client->log, "mqtt_pal_sendall(len=%d)", len); + mws_debug(client->log, "mqtt_pal_sendall(len=%d)", len); #endif - int ret = ws_client_send(mqtt_wss_client->ws_client, WS_OP_BINARY_FRAME, buf, len); + int ret = ws_client_send(client->ws_client, WS_OP_BINARY_FRAME, buf, len); if (ret >= 0 && (size_t)ret != len) { #ifdef DEBUG_ULTRA_VERBOSE - mws_debug(mqtt_wss_client->log, "Not complete message sent (Msg=%d,Sent=%d). Need to arm POLLOUT!", len, ret); + mws_debug(client->log, "Not complete message sent (Msg=%d,Sent=%d). Need to arm POLLOUT!", len, ret); #endif - mqtt_wss_client->mqtt_didnt_finish_write = 1; + client->mqtt_didnt_finish_write = 1; } return ret; } @@ -590,12 +583,18 @@ int mqtt_wss_connect(mqtt_wss_client client, char *host, int port, struct mqtt_c if (client->sockfd > 0) close(client->sockfd); - client->sockfd = socket(AF_INET, SOCK_STREAM, 0); + client->sockfd = socket(AF_INET, SOCK_STREAM | DEFAULT_SOCKET_FLAGS, 0); if (client->sockfd < 0) { mws_error(client->log, "Couldn't create socket()"); return -1; } +#ifndef SOCK_CLOEXEC + int flags = fcntl(client->sockfd, F_GETFD); + if (flags != -1) + (void) fcntl(client->sockfd, F_SETFD, flags| FD_CLOEXEC); +#endif + int flag = 1; int result = setsockopt(client->sockfd, IPPROTO_TCP, @@ -680,11 +679,6 @@ int mqtt_wss_connect(mqtt_wss_client client, char *host, int port, struct mqtt_c } } - uint8_t mqtt_flags = (mqtt_params->will_flags & MQTT_WSS_PUB_QOSMASK) << 3; - if (mqtt_params->will_flags & MQTT_WSS_PUB_RETAIN) - mqtt_flags |= MQTT_CONNECT_WILL_RETAIN; - mqtt_flags |= MQTT_CONNECT_CLEAN_SESSION; - client->mqtt_keepalive = (mqtt_params->keep_alive ? mqtt_params->keep_alive : 400); mws_info(client->log, "Going to connect using internal MQTT 5 implementation"); |