Windows fixes.

pull/2223/merge
Roger A. Light 3 years ago
parent 86117d44d4
commit 11b16756cb

@ -1223,7 +1223,12 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
if(pub_or_sub != CLIENT_SUB){
goto unknown_option;
}
#ifdef WIN32
fprintf(stderr, "Error: --watch not supported on Windows.\n\n");
return 1;
#else
cfg->watch = true;
#endif
}else if(!strcmp(argv[i], "--will-payload")){
if(i==argc-1){
fprintf(stderr, "Error: --will-payload argument given but no will payload specified.\n\n");

@ -116,7 +116,9 @@ struct mosq_config {
long session_expiry_interval;
int random_filter; /* sub */
int transport;
#ifndef WIN32
bool watch; /* sub */
#endif
#ifdef WITH_SOCKS
char *socks5_host;
int socks5_port;

@ -852,7 +852,7 @@ static void rand_init(void)
#endif
}
#ifndef WIN32
static void watch_print(const struct mosquitto_message *message)
{
struct watch_topic *item = NULL;
@ -873,6 +873,7 @@ static void watch_print(const struct mosquitto_message *message)
}
printf("\e[%d;1H", item->line);
}
#endif
void print_message(struct mosq_config *lcfg, const struct mosquitto_message *message, const mosquitto_property *properties)
@ -883,9 +884,12 @@ void print_message(struct mosq_config *lcfg, const struct mosquitto_message *mes
long r = 0;
#endif
#ifndef WIN32
if(lcfg->watch){
watch_print(message);
}
#endif
if(lcfg->random_filter < 10000){
#ifdef WIN32
rand_s(&r);
@ -920,20 +924,24 @@ void print_message(struct mosq_config *lcfg, const struct mosquitto_message *mes
fflush(stdout);
}
}
#ifndef WIN32
if(lcfg->watch){
printf("\e[%d;1H\n", watch_max-1);
}
#endif
}
void output_init(struct mosq_config *lcfg)
{
rand_init();
#ifndef WIN32
if(lcfg->watch){
printf("\e[2J\e[1;1H");
printf("Broker: %s\n", lcfg->host);
}
#endif
#ifdef WIN32
/* Disable text translation so binary payloads aren't modified */
_setmode(_fileno(stdout), _O_BINARY);
(void)_setmode(_fileno(stdout), _O_BINARY);
#endif
}

@ -41,6 +41,7 @@ IF( CJSON_FOUND )
set_target_properties(cJSON
PROPERTIES
IMPORTED_LOCATION "${CJSON_LIBRARY}"
IMPORTED_IMPLIB "${CJSON_LIBRARY}"
)
ELSE()
SET( CJSON_DIR "" CACHE STRING

@ -45,11 +45,15 @@
#endif
#ifdef WIN32
# ifndef strcasecmp
# define strcasecmp strcmpi
# endif
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define strtok_r strtok_s
# define strerror_r(e, b, l) strerror_s(b, l, e)
# ifdef _MSC_VER
# include <basetsd.h>
typedef SSIZE_T ssize_t;
# endif
#endif

@ -18,7 +18,6 @@ Contributors:
#include "config.h"
#include <pthread.h>
#include <stdbool.h>
#include <string.h>

@ -19,9 +19,11 @@ Contributors:
#include "config.h"
#include <assert.h>
#include <arpa/inet.h>
#include <errno.h>
#include <string.h>
#ifndef WIN32
# include <arpa/inet.h>
#endif
#ifdef WITH_BROKER
# include "mosquitto_broker_internal.h"

@ -77,7 +77,7 @@ static time_t last_report = 0;
static int callback_tick(int event, void *event_data, void *userdata)
{
struct timespec ts;
time_t sec;
char topic[40];
char payload[40];
int slen;
@ -87,9 +87,9 @@ static int callback_tick(int event, void *event_data, void *userdata)
UNUSED(event_data);
UNUSED(userdata);
clock_gettime(CLOCK_REALTIME, &ts);
if(last_report + 10 < ts.tv_sec){
last_report = ts.tv_sec;
sec = time(NULL);
if(last_report + 10 < sec){
last_report = sec;
for(i=0; i<SIZE_COUNT; i++){
if(size_counts[i] != last_size_counts[i]){

@ -98,7 +98,7 @@ static int callback_tick(int event, void *event_data, void *userdata)
for(int i=1; i<MAX_EVT+1; i++){
if(evt_counts[i] != last_evt_counts[i]){
slen = snprintf(payload, sizeof(payload), "%ld", evt_counts[i]);
slen = snprintf(payload, sizeof(payload), "%lld", evt_counts[i]);
mosquitto_broker_publish_copy(NULL, evt_topics[i], slen, payload, 0, 1, NULL);
last_evt_counts[i] = evt_counts[i];
}

@ -23,6 +23,9 @@ Contributors:
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#ifdef WIN32
# include <direct.h>
#endif
#include "mosquitto.h"
#include "mosquitto_broker.h"
@ -66,7 +69,11 @@ static int get_db_file(struct mosquitto_opt *options, int option_count)
persistence_location = mosquitto_persistence_location();
if(persistence_location){
#ifdef WIN32
(void)mkdir(persistence_location);
#else
mkdir(persistence_location, 0770);
#endif
plg_data.db_file = malloc(strlen(persistence_location) + 1 + strlen("/mosquitto.sqlite3"));
if(!plg_data.db_file){
mosquitto_log_printf(MOSQ_LOG_INFO, "Sqlite persistence: Out of memory.");

@ -886,18 +886,34 @@ int db__messages_easy_queue(struct mosquitto *context, const char *topic, uint8_
*/
uint64_t db__new_msg_id(void)
{
#ifdef WIN32
FILETIME ftime;
uint64_t ftime64;
#else
struct timespec ts;
#endif
uint64_t id;
uint64_t tmp;
time_t sec;
long nsec;
id = db.node_id_shifted; /* Top 10-bits */
#ifdef WIN32
GetSystemTimePreciseAsFileTime(&ftime);
ftime64 = (((uint64_t)ftime.dwHighDateTime)<<32) + ftime.dwLowDateTime;
tmp = ftime64 - 116444736000000000LL; /* Convert offset to unix epoch, still in counts of 100ns */
sec = tmp / 10000000; /* Convert to seconds */
nsec = (long)(tmp - sec)*100; /* Remove seconds, convert to counts of 1ns */
#else
clock_gettime(CLOCK_REALTIME, &ts);
tmp = (ts.tv_sec - MOSQ_UUID_EPOCH) & 0x7FFFFFFF;
sec = ts.tv_sec;
ns = ts.tv_nsec;
#endif
tmp = (sec - MOSQ_UUID_EPOCH) & 0x7FFFFFFF;
id = id | (tmp << 23); /* Seconds, 31-bits (68 years) */
tmp = (ts.tv_nsec & 0x7FFFFF80); /* top 23-bits of the bottom 30 bits (1 billion ns), ~100 ns resolution */
tmp = (nsec & 0x7FFFFF80); /* top 23-bits of the bottom 30 bits (1 billion ns), ~100 ns resolution */
id = id | (tmp >> 7);
while(id <= db.last_db_id){

Loading…
Cancel
Save